我尝试逐字符读取文件字符。不幸的是,Java 在从文件中读取字符时会忽略 EOF。
FileReader fileReader = new FileReader(fileText);
char c;
String word = "";
List<String> words = new ArrayList<String>();
while ((c = (char) fileReader.read()) != -1) {
System.out.println(c);
if (c != ' ') {
word = word + c;
}
else {
words.add(word + " ");
word = "";
}
}
它应该在读取文件后分解,但它永远不会停止运行....