第二次将“something”这个词添加到文件中并打印“atext has added”但它将其视为空文件....
什么..
public class ReadFile { public ReadFile() { } public boolean readFile() { boolean success = false; String file_name = "source/text.txt"; try { FileReader file = new FileReader(file_name); BufferedReader read = new BufferedReader(file); BufferedWriter bf = new BufferedWriter(new FileWriter (file_name)); if (read.readLine() != null) { bf.append("something"); System.out.println("a text has been added!!"); } else { bf.append(file_name); System.out.println("File updated"); } read.close(); bf.close(); success = true; } catch(IOException e) { e.getMessage(); } return success; } public static void main(String[] args) { // TODO Auto-generated method stub ReadFile rf = new ReadFile(); rf.readFile(); }}
当文件不为空时,应该在EOF中添加“something”
鸿蒙传说
慕村225694
神不在的星期二
相关分类