FileOutpuStream流的问题

来源:互联网 发布:初级java最大值最小值 编辑:程序博客网 时间:2024/06/06 00:53

前几天,写输出流的时候遇到了问题,我的图片写的时候怎么也加载不出来了

public static void main(String[] args) {    try {        File f = new File("e:/e/123456.jpg");        FileInputStream ff = new FileInputStream(f);        BufferedInputStream bf = new BufferedInputStream(ff);        FileOutputStream fo = new FileOutputStream(f.getAbsolutePath());        BufferedOutputStream bo = new BufferedOutputStream(fo);        byte[]b=new byte[1024];        int len=0;        while((len=bf.read(b))!=-1) {            bo.write(b);            bo.flush();        }        bo.close();        fo.close();        bf.close();        ff.close();    } catch (Exception e) {        // TODO Auto-generated catch block        e.printStackTrace();    }}
然后就跪了;经过高人指点后知道了

 FileOutputStream fo = new FileOutputStream(f.getAbsolutePath());
是这句代码出问题了,其实是输出流清空了图片的内容导致读不出来。点击打开链接。所以读图片要换一个新的名字或路径

原创粉丝点击