本帖最后由 MK_Chan 于 2014-4-1 16:57 编辑
- import java.io.* ;
- public class Demo01
- {
- public static void main(String args[])
- {
- File f= new File("F:\\java\\Demoio02\\1.txt") ;
- OutputStream out = null ;
- try
- {
- null = new FileOutputStream(f) ;
- }
- catch(Exception e)
- {}
- String str = "Hello World" ;
- byte b[] = str.getBytes() ;
- try
- {
- out.write(b);
- }
- catch(Exception e)
- {}
- try
- {
- out.close() ;
- }
- catch(Exception e)
- {}
- }
- }
- 想问一下,为什么上面的代码这样写就会出错呢?
- import java.io.* ;
- public class Demo01
- {
- public static void main(String args[])
- {
- File f= new File("F:\\java\\Demoio02\\1.txt") ;
- try
- {
- OutputStream out = new FileOutputStream(f) ;
- }
- catch(Exception e)
- {}
- String str = "Hello World" ;
- byte b[] = str.getBytes() ;
- try
- {
- out.write(b);
- }
- catch(Exception e)
- {}
- try
- {
- out.close() ;
- }
- catch(Exception e)
- {}
- }
- }
|