java缓冲字节流复制文件,逐个字节读取、写入

package cwj.bbb;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

class StreamTest
{
	public static void main(String[] args) throws IOException
	{
		/*把路径下的文件/home/cwjy1202/hadoop/javaTest/input01.txt
		 * 以字节缓冲输出流的方式复制到/home/cwjy1202/hadoop/javaTest/input013.txt
		 * */
		File file = new File("/home/cwjy1202/hadoop/javaTest/input01.txt");
		InputStream bis = new BufferedInputStream(new FileInputStream(file));
		OutputStream bos = new BufferedOutputStream(new FileOutputStream("/home/cwjy1202/hadoop/javaTest/input013.txt"));
		
		//逐个字节读取
		int len = bis.read();
		while(-1 != len)
		{
			//逐个字节写入
			bos.write(len);
			len = bis.read();
		}
		
		//强制把缓冲区的数据输出
		bos.flush();
		bos.close();
		bis.close();
	}
}


你可能感兴趣的:(java,缓冲字节流)