0
我有一个文本文件,它存储有关用户的数据,包括用户名,密码和其他详细信息。在文本文件中,每个用户的数据存储在一行中并使用“,”分隔。我正在尝试从文件中读取并列出所有用户名。用户名是第一行从文本文件读取到文本字段java
在下面的代码中,我管理读取和输出,但只有文本文件中的最后一个。我怎样才能读取和输出所有。
try {
File f = new File("/Users/Nisham/Desktop/javapwd.txt");
Scanner sc = new Scanner(f);
while(sc.hasNextLine()){
String line = sc.nextLine();
String[] details = line.split(",");
String name = details[0];
//int age = Integer.parseInt(details[2]);
jTextArea1.setText(name);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
这个问题有没有关系网络,NetBeans中,或在BufferedReader中的jTextArea1文本。 – shmosel