package com.zypcy.readbigfile;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.Scanner;
/**
* 读取大文件
* 分别测试不同文件流IO与NIO读取的效率
* 因文件很大,机器可用内存较小,无法一次读取全部内容,需要读取固定大小的数据
* @author zhuyu
*/
public class Demo {
public static void main(String[] args) {
String filePath = "D:\project\java\workspace\DemoThread\src\com\zypcy\readbigfile\bigdata.zip";
String newPath = "D:\project\java\workspace\DemoThread\src\com\zypcy\readbigfile\output.zip";
try {
File file = new File(filePath);
if(!file.exists()){
return;
}
File newFile = new File(newPath);
//randomAccessRead(file ,newFile);
//测试:读取1.23GB文件耗时:8768ms
//bufferedRead(file ,newFile);
//测试:读取1.23GB文件耗时:2202ms
//sca