我在扫描给定文件中的某些单词并将它们分配给变量时遇到问题,到目前为止,我选择使用 Scanner 而不是 BufferedReader 因为它更熟悉。我得到了一个文本文件,而这个特定的部分我正在尝试读取每行的前两个单词(可能是无限行),并可能将它们添加到各种数组中。这就是我所拥有的:
File file = new File("example.txt");
Scanner sc = new Scanner(file);
while (sc.hasNextLine()) {
String line = sc.nextLine();
String[] ary = line.split(",");
我知道距离很远,但是我是编码新手,无法越过这堵墙……
一个示例输入将是...
ExampleA ExampleAA, <other items seperated by ",">
ExampleB ExampleBB, <other items spereated by ",">
...
和建议的输出
VariableA = ExampleA ExampleAA
VariableB = ExampleB ExampleBB
...