- [code][b]import java.io.FileOutputStream ;
- import java.io.File ;
- import java.io.OutputStream ;
- public class OutputStreamDemo{
- public statiic void main(String[] args)throws Exception{
- File f = new File("test.txt") ;
- OutputStream out = null ;
- out = new FileOutputStream(f );
- String str = "Hello World!" ;
- byte[] b = str.getBytes() ;
- out.write(b) ;
- //out.close() ;
- }
- }[/b]
复制代码- [b]import java.io.Writer;
- import java.io.File ;
- import java.io.FileWriter;
- public class WriterDemo{
- public statiic void main(String[] args)throws Exception{
- File f = new File("test.txt") ;
- Writer writer= null ;
- writer = new FileWriter(f );
- String str = "Hello World!" ;
- out.write(b) ;
- //out.close() ;
- }
- }[/b]
复制代码 [/code]
问题是为什么第一个的文件中有内容,但是第二中没有呢?我两个程序的输出流都故意没有关闭 |