⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fastcopyfile.java

📁 nanjing university cs 的java课件。 对新手很有用。付课件中源码。
💻 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 + -