java文件读取有两种类型,我这里的是字节流的读取操作
package test1;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Test {
public static void main(String[] args) throws IOException {
int length=0;
File file=new File("src/123.txt");
File file2=new File("001.txt");
FileInputStream fileInputStream=new FileInputStream(file);
FileOutputStream fileOutputStream=new FileOutputStream(file2);
byte []arr=new byte[1024];
while((length=fileInputStream.read(arr))>0) {
String string=new String(arr, 0, length);
System.out.println(string);
fileOutputStream.write(arr);
}
fileInputStream.close();
fileOutputStream.close();
}
}