- package com.io;
- import java.io.*;
- public class TestCopy
- { public static void main(String[] args)
- {
- InputStream is=null;
- OutputStream os=null;
- try
- {
- // 读取文件 english.txt
- is=new FileInputStream(new File("res/1.png"));
- // 实列化一个写入流
- os=new FileOutputStream(new File("res/copy.png"));
- int l;
- // 一边读 一边写入
- while((l=is.read())!=-1)
- {
- os.write(l);
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- finally
- {
- try
- {
- is.close();
- os.close();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- }
- }
来源: http://www.bubuko.com/infodetail-2659869.html