package cwj.bbb;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class StreamTest
{
public static void main(String[] args) throws IOException
{
/*
* 把路径下的文件/home/cwjy1202/hadoop/javaTest/input01.txt
* 以字节流的方式复制到/home/cwjy1202/hadoop/javaTest/input012.txt
* */
File file = new File("/home/cwjy1202/hadoop/javaTest/input01.txt");
InputStream fis = new FileInputStream(file);
OutputStream fos = new FileOutputStream("/home/cwjy1202/hadoop/javaTest/input012.txt");
byte[] b = new byte[1024];
//数组读取
int len = fis.read(b);
while(-1 != len)
{
//数组写入
fos.write(b, 0, len);
len = fis.read(b);
}
//把缓冲区数据强行输出
fos.flush();
fos.close();
fis.close();
}
}
java字节流的方式复制一个文件,按数组读取和写入
最新推荐文章于 2021-03-02 04:25:09 发布