package myPro1;
import java.io.*;
//读取大文件
package myPro1;
import java.io.*;
//读取大文件
public class TestMain {
public static void main(String[] args) {
FileInputStream fis = null;
FileOutputStream fos = null;
try {
fis = new FileInputStream("C:/123.txt");
fos = new FileOutputStream("C:/to23.txt");
byte[] b = new byte[1024];
while (true) {// 循环读取数据
// 一次读取1024个字节
int length = fis.read(b, 0, b.length);
// 如果返回的字节为-1,代表已经没有数据
// break,跳出循环
if (length == -1) {
break;
}
fos.write(b, 0, length);// 一次写入1024个字节
}
} catch (Exception e) {
System.out.println(e);
} finally {//关闭输入输出流
try {
fis.close();
fos.close();
} catch (IOException e) {
System.out.println(e);
}
}
}
}
Java.io读取大文件
最新推荐文章于 2021-06-25 12:48:40 发布