filecopy.java

来自「合并几个数据库结构相同的数据库文件。hsql数据库文件合并」· Java 代码 · 共 27 行

JAVA
27
字号
package merge;

import java.nio.channels.*;
import java.io.*;

public class FileCopy{ 
	public static void main(String args[]){   
		try {  
			FileCopy j = new FileCopy();    
			j.copyFile(new File("1.txt"),new File("1copy.txt"));  
			File f=new File("1copy.txt");
			f.renameTo(new File("1c.txt"));
		}catch (Exception e) {   
			e.printStackTrace();    
		}
		}  
	public void copyFile(File in, File out) throws Exception {   
		FileChannel sourceChannel = new FileInputStream(in).getChannel();   
		FileChannel destinationChannel = new FileOutputStream(out).getChannel();  
		sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);  
		// or    
		// destinationChannel.transferFrom(sourceChannel, 0, sourceChannel.size()); 
		sourceChannel.close();    
		destinationChannel.close();   
		} 
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?