BufferedInputStream、BufferedOutputStream

赋值图片例子:

import java.io.*;
class  CopyMp3
{
	public static void main(String[] args) 
	{
		CopyPic();
	}

	public static void CopyPic()
	{
		FileInputStream fileInput = null;
		FileOutputStream fileOutput = null;
		try
		{
			fileInput = new FileInputStream("C:\\1.jpg");
			fileOutput = new FileOutputStream("C:\\2.Jpg");
			BufferedInputStream bufInput = new BufferedInputStream(fileInput);
			BufferedOutputStream bufOutput = new BufferedOutputStream(fileOutput);
			byte [] bt = new byte[1024];
			int len = 0;
			while((len = bufInput.read(bt)) != -1)
			{
				bufOutput.write(bt);
				bufOutput.flush();
			}
		}
		catch (IOException ex)
		{
			ex.printStackTrace();
		}
		finally
		{
			try
			{
				if(fileInput != null)
				{
					fileInput.close();
				}
				if(fileOutput != null)
				{
					fileOutput.close();
				}
			}
			catch (IOException ex)
			{
				ex.printStackTrace();
			}
		}
	}
}


posted @ 2015-01-17 09:31  静以养身 俭以养德  阅读(153)  评论(0编辑  收藏  举报