开发者社区> 问答> 正文

java file操作问题

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 了, 感觉上自己应该没错啊,就是输不出我要的结果。

展开
收起
蛮大人123 2016-02-28 15:44:08 1902 0
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪

    你都知道它catch到exception了,看一下catch到的是什么就可以了。

    2019-07-17 18:49:40
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载