【发布时间】:2014-05-07 09:20:16
【问题描述】:
我控制读取数据文件的外部循环不正确,有人可以向我解释如何让循环打印整个数据文件而不仅仅是数据文件中的第一个单词吗?
public static void display() throws IOException, FileNotFoundException {
Scanner infile = new Scanner(new FileReader("G:\\DataFileDS.txt"));
StringTokenizer token = new StringTokenizer(infile.nextLine());
StringElement str = new StringElement();
while(token.hasMoreTokens()) {
str.setString(token.nextToken());
stringList.insert(str);
}
stringList.print();
int n = stringList.listSize();
for(int i = 0; i < n - 1; ++i) {
System.out.println(stringList.retrieveAt(i) + " " + stringList.retrieveAt(i+1));
}
}
【问题讨论】: