java file操作 问题

import java.io.*;

public class file2 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        File f= new File("D\\xx\\te.txt") ; 
        OutputStream out = null ; 

        try
        {

            out = new FileOutputStream(f) ; 

        }
        catch(Exception e)
        {
            System.out.println("asdas");
        }

        String a =new String("sadasdas")  ;
        byte[] b = a.getBytes() ;


        try
        { 
            out.write(b);

        }
        catch(Exception e)
        {
            System.out.println("asdas");
        }

        try
        {
            out.close() ;

        }
        catch(Exception e)
        {
            System.out.println("asdas");
        }

        InputStream in = null ; 
        try
        {
            in =    new FileInputStream(f ) ; 

        }
        catch(Exception e)
        {
            System.out.println("asdas");
        }

        byte[] d = new byte[1024] ; 
        int i= 0 ; 
        try
        {
            i = in.read(d) ; 
            in.close() ;

            System.out.println(i);
        }
        catch(Exception e)
        {
            System.out.println("asdas");
        }


        System.out.println(i);

    }

}

调试了一下,发现好像所有的try都进catch 了, 感觉上自己应该没错啊,就是输不出我要的结果。

阅读 3.6k
3 个回答

这问题就不该给答案,你都知道它catch到exception了,就不去看一下catch到的是什么东西么?

不知道你出的问题是什么。。。。

File f= new File("D\\xx\\te.txt");

看看 路径 正确吗?

起码得是这样吧:

File f= new File("D:\\xx\\te.txt");

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题