我是Java的新手,我正在尝试
检查文件是否存在 ==>如果文件不存在,则在文件中写入值“0,0”(如果它是新文件)
阅读文件的第一行
我遇到的问题是,一旦写完这一行,我就必须再次读同一行来检查一下。但指针移动到下一行。那我该怎么做呢?
File f1 = new File(DirPath);
FileReader fileReader = new FileReader(DirPath);
BufferedReader brTest = new BufferedReader(fileReader);
if (brTest.readLine() == null) {
printData = 0 + "," + 0;
p.println(printData);
}
line = brTest.readLine(); // I have to read the line I wrote i.e 0, 0
text = brTest .readLine();