JavaEclipse从一个文件中获取名称和数字,按字母顺序排序到一个新文件中,按数字排序到一个新文件中
这学期我刚开始在大学学习Java,虽然我可以做一些更基本的事情,也可以编写简单的程序,但我在编写这个程序时遇到了一个障碍。我还没有学会树(似乎是一种常见的修复方法),我需要帮助整理东西和创建新文件
我的文件,玩家和;分数txt包含以下内容:
Bruce 127
Elayna 144
Lisa 153
Marcus 188
Amber 133
Ryan 149
Dorian 099
Joel 175
Jenna 101
所以基本上我需要根据名字顺序,然后根据分数,将这个列表排序到一个文件中。到目前为止,我的代码是这样的
import java.io.*;
import java.util.*;
/**
* Bruce P., November 14, 2013, CSC 131
* This program uses a file consisting of members of a bowling league. Each line has one name and the average score of the player.
* The program reads the file and then creates two new files in which one is sorted by alphabetical order of the player's name
* and the other is sorted in numerical order based on the player's score.
*
*/
public class MembersAndScores
{
public static void main(String[] args) throws IOException
{
File inputFile = new File("Players&Score.txt");
if (!inputFile.exists())
{
System.out.println("File Players&Score.txt was not found.");
System.exit(0);
}
Scanner input = new Scanner(inputFile);
String line;
File scoreSort = new File("SortedByName.txt");
PrintWriter writer = new PrintWriter(scoreSort);
}
}
我可能把事情搞砸了,或者我请求帮助时看起来很傻。我只是不明白这一部分以及如何做到这一点。感谢您的帮助
# 1 楼答案
这将根据名称进行排序。我将很快添加分数代码
您可以获得阵列的更多详细信息。sort()here