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

📄 copyfile.java

📁 java应用举例2
💻 JAVA
字号:
import java.io.*;

public class CopyFile {
	public static void main(String args[]) throws IOException {
		//检查程序参数
		if(args.length != 2 ) {
			System.out.println("程序参数不正确!!");
		} else {
			//调用自定义的拷贝函数
			try{
				Paste(args[0],args[1]);
			} catch (Exception e0) {
				System.out.println("文件读取错误!!");
			}
		}
	}

	public static void Paste(String rls, String test) throws IOException {
		//建立源文件与目标文件
		File src = new File(rls);
		File obj = new File(test);
		//确定传入的源文件是否存在
		if(src.exists() == false) {
			System.out.println("源文件不存在!!");
		} else {
			//建立文件输入流
			FileInputStream   in = null;
			//建立文件输出流
			FileOutputStream out = null;
			try {
				in  = new FileInputStream(src);
				out = new FileOutputStream(obj);
				//创建保存文件内容的容器
				byte buffer[] = new byte[4096];
				//建立输入流缓冲区
				int  read;
				//读源文件直到文件末尾
				while((read = in.read(buffer)) != -1) {
					out.write(buffer,0,read);
				}
				in.close();
				out.close();
			} catch(IOException e1) {
				System.out.println("文件拷贝失败!!");
			}
		}
	}
}


⌨️ 快捷键说明

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