Java IO流 之 文件复制

http://www.verejava.com/?id=16994676228912

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.verejava.com/?id=16994676228912

猜你喜欢

转载自blog.csdn.net/verejava/article/details/80590142