开发者社区 问答 正文

字节流复制图片的问题

import java.io.*;
class Lee{
public static void main (String[] args){
FileOutputStream fos=null;
FileInputStream fis=null;
try{
fos=new FileOutputStream("D:\毕向东视频\9.png");
fis=new FileInputStream("D:\毕向东视频\99.png");
byte [] buf=new byte[1024];
int len=0;
while((len=fis.read(buf))!=-1)
{
fos.write(buf,0,len);
        }
       }
    catch(IOException e){
        throw new RuntimeException("复制失败");
    }
    finally{
            try{
                if(fis!=null)
                fis.close();

                }
            catch(IOException e){
                throw new RuntimeException("读取失败");
            }
        }
    }
}

展开
收起
蛮大人123 2016-06-07 15:55:35 1896 分享 版权
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪
     class Lee {
        public static void main(String[] args) {
            FileOutputStream fos = null;
            FileInputStream fis = null;
            try {
                fos = new FileOutputStream("D:/copy.jpg");
                fis = new FileInputStream("D:/照片打印/picture2.jpg");
                byte[] buf = new byte[2048];
                int len = 0;
                while ((len = fis.read(buf)) != -1) {
                    fos.write(buf, 0, len);
                }
                fos.flush();
            } catch (IOException e) {
                e.printStackTrace();
                throw new RuntimeException("复制失败");
            } finally {
                try {
                    if (fis != null)
                        fis.close();
                    fos.close();
                } catch (IOException e) {
                    throw new RuntimeException("读取失败");
                }
            }
        }
    }
    2019-07-17 19:30:21
    赞同 展开评论
问答地址: