标签:流的关闭问题
package com.hephec;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
public class OutputStreamTest{
public static void main(String[] args) throws Exception{
OutputStream out=new FileOutputStream(new File("E:"+File.separator+"test.txt"));
String str="zhangsan";
byte[] b=str.getBytes();//将字符串转化为字节数组
out.write(b);
//out.close();//未关闭流
}
}
//result:zhangsan
//虽然没有关闭字节流,但是文件中依然有内容输出,证明字节流是直接操作文件本身的
package com.hephec;
import java.io.File;
import java.io.FileWriter;
import java.io.Writer;
public class OutputStreamTest{
public static void main(String[] args) throws Exception{
Writer writer=new FileWriter(new File("E:"+File.separator+"test.txt"));
String str="zhangsan";
byte[] b=str.getBytes();//将字符串转化为字节数组
writer.write(b);
//writer.close();//未关闭流
}
}
//result:
标签:流的关闭问题
原文地址:http://blog.csdn.net/hephec/article/details/39394581