copyfile.java

来自「nanjing university cs 的java课件。 对新手很有用。付」· Java 代码 · 共 29 行

JAVA
29
字号
import java.io.*;
import java.nio.*;
import java.nio.channels.*;

public class CopyFile{
	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.allocate(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 + =
减小字号Ctrl + -
显示快捷键?