字节流复制文本文件
package com.czie.iot1913.lps.IO.InPutStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* FileName: FileCopyTest01
* Author: lps
* Date: 2022/3/23 21:42
* Sign:刘品水 Q:1944900433
*/
public class FileCopyTest01 {
public static void main(String[] args) throws IOException {
//在本目录创建txt文件
File file01 = new File("F:\\JavaCode\\窗里窗外.txt");
//读取E盘下txt内容
FileInputStream fis = new FileInputStream("E:\\itcast\\窗里窗外.txt");
FileOutputStream fos = new FileOutputStream("F:\\JavaCode\\窗里窗外.txt");
int by;
while ((by=fis.read())!=-1){
fos.write(by);
}
fos.close();
fis.close();
}
}
package com.czie.iot1913.lps.IO.InPutStream;
import java.io.FileInputStream;
import java.io.IOException;
/**
* FileName: FileInPutStreamTEst02
* Author: lps
* Date: 2022/3/23 23:05
* Sign:刘品水 Q:1944900433
*/
public class FileInPutStreamTest02 {
public static void main(String[] args) throws IOException {
//创建字节输入流对象
FileInputStream fis = new FileInputStream("F:\\JavaCode\\fos.txt");
/*//调用字节输入流对象的读取数据
//int read(byte[] b)
//读到 b.length从输入流到字节数组数据字节。
byte[] bys = new byte[5];
int len = fis.read(bys);
System.out.println(len);
//System.out.println(new String(bys));
System.out.println(new String(bys,0,len));
//有\r\n!!!!
len = fis.read(bys);
System.out.println(len);
//System.out.println(new String(bys));
System.out.println(new String(bys,0,len));
//int read(byte[] b, int off, int len)
//读到 len从输入流到字节数组数据字节。
len = fis.read(bys);
System.out.println(len);
System.out.println(new String(bys,0,len));
*/
byte[] bys = new byte[1024];//1024及其整数倍
int len ;
while ((len=fis.read(bys))!=-1){
System.out.println(new String(bys,0,len));
}
//释放内存
fis.close();
}
}