【发布时间】:2020-04-28 16:09:51
【问题描述】:
我使用datainputstream.readUTF()方法读取带有数据的文本文件,总是EOF Exception,我不明白这是为什么?
public void readDataDemo() throws IOException {
RandomAccessFile randomAccessFile = new RandomAccessFile("temp/buf.txt", "rw");
String str = randomAccessFile.readUTF();
randomAccessFile.close();
}
【问题讨论】:
-
该方法不适用于读取文本文件。 Read the DataInput documentation。 (你可能想要Files.readString。)
-
对于您要查找的内容,有很多关于 SO 的相关问题。 This is one、this is another one 和 here's one more。
标签: java