📄 fastcopyfile.java
字号:
import java.io.*;
import java.nio.*;
import java.nio.channels.*;
public class FastCopyFile{
public static void main(String args[]) throws Exception{
String infile = args[0], outfile = args[1];
long start = System.currentTimeMillis();
FileInputStream fis = new FileInputStream(infile);
FileChannel fcin = fis.getChannel();
FileOutputStream fos = new FileOutputStream(outfile);
FileChannel fcout = fos.getChannel();
ByteBuffer buffer = ByteBuffer.allocateDirect(1024);
while(true){
int ret = fcin.read(buffer);
if(ret == -1)
break;
buffer.flip();
fcout.write(buffer);
buffer.clear();
}
long end = System.currentTimeMillis();
System.out.println("Elapsed Time: " + (end - start) + " milliseconds.");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -