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

📄 filecopier.java

📁 1.文件和目录管理
💻 JAVA
字号:
/**
 * Class FileCopier to copy file
 */

package file;
import java.io.*;
import java.io.File;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


class FileCopier {
	
	public File sourceFile,destFile;
	
	/**
	 * method to copy a file from source file to destination file
	 * @param sf the source file name
	 * @param df the destination file name
	 */
	public void copy(String sf,String df) {
		
		sourceFile = new File(sf);
		destFile = new File(df);
		
		try{
			
			int confirm = JOptionPane.YES_OPTION;
			if(!sourceFile.exists()) 
				throw new NoSuchFileException(sf);
			if(sourceFile.isDirectory())
				throw new IsDirectoryException(sf);
			if(!destFile.exists()){
				confirm = JOptionPane.showConfirmDialog(null,
					"The destinate file is not exist!\n	Create it ?",
					"notice",JOptionPane.YES_NO_OPTION);
					
			}
			
			else {
				
				confirm = JOptionPane.showConfirmDialog(null,
					"The file " + df + " is exist!\n	Overwrite it ?",
					"Notice",JOptionPane.YES_NO_OPTION);
			}
			
			if(confirm == JOptionPane.YES_OPTION) {
			
				FileInputStream in = new FileInputStream(sf);
				BufferedInputStream inBuffer = new BufferedInputStream(in);
				
				FileOutputStream out = new FileOutputStream(df);
				BufferedOutputStream outBuffer = new BufferedOutputStream(out);
				int c;
				while((c = inBuffer.read()) != -1){
					outBuffer.write(c);
				}
				outBuffer.flush();
				in.close();
				out.close();
				JOptionPane.showMessageDialog(null,
					"Copy over !");
			}
		}catch(IOException ioe){
		}catch(Exception e){
		}	
	} 	
}

⌨️ 快捷键说明

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