本帖最后由 王建旺 于 2013-3-28 14:22 编辑
import java.io.*;
class BufferedWriterDemo
{
public static void main(String[] args)
{
FileWriter fw = null;
BufferedWriter bufw = null;
try
{
fw = new FileWriter("demo.txt");
bufw = new BufferedWriter(fw);
bufw.write("dhhghd");
bufw.flush();
}
catch (IOException e)
{
throw new RuntimeException("读写失败");
}
finally
{
try
{
if(bufw!=null)
bufw.close();
}
catch (IOException e)
{
throw new RuntimeException("写入关闭失败");
}
}
}
}
这里面的bufw.flush()可以不写吗,或者是要write多次的时候,是不是也可以不用写,数据也会写入到demo.txt中
|