【发布时间】:2013-11-27 02:38:19
【问题描述】:
我正在尝试一些基本的 Java I/O 操作,我尝试运行以下代码:
public static void main(String[] args) {
File file = new File("fileWrite2.txt"); // create a File object
try {
FileWriter fr = new FileWriter(file);
PrintWriter pw = new PrintWriter(file); // create a PrintWriter that will send its output to a Writer
BufferedWriter br = new BufferedWriter(fr);
br.write("sdsadasdsa");br.flush();br.append("fffff");br.flush();
pw.println("howdy"); // write the data
pw.println("folks");
pw.flush();
pw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
当我运行上述程序时,我在创建的文件中得到以下输出:
howdy
folks
f
谁能解释为什么'f'出现在最后一行?
【问题讨论】:
标签: java file-io io printwriter bufferedwriter