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

📄 copy.java

📁 这个文件是java对文件的操作
💻 JAVA
字号:
import java.io.*;

public class Copy 
{
    public static void main(String[] args) 
    {
	//声明一个文件读入流
	FileReader in =null;
	//声明一个文件写入流
	FileWriter out =null;
	
	//提示信息
	if(args.length !=2)
	{
		System.out.println("Usage:you must input the file path .");
		System.out.println("example: java Copy F:\\book\\2\\example\\file\\test.txt test2.txt");
		System.exit(1);
	}
	
	try
	{
		//构造输入文件
		File inputFile = new File(args[0]);
		//构造输出文件
		File outputFile = new File(args[1]);

        	in = new FileReader(inputFile);
        	out = new FileWriter(outputFile);
        	int c;

        	//按字符读入文件,并原样输出
        	while ((c = in.read()) != -1)
           		out.write(c);

		//清理输入输出流
        	in.close();
        	out.close();
        	
        	//成功提示信息
        	System.out.println("ok..."+args[0]+" be copied to "+args[1]);
        }
        catch(IOException e)
        {
        	e.printStackTrace();
        }
        finally
        {
        	//必须关闭所有的流
        	if(in!=null) try{in.close();}catch(IOException e){}
        	if(out!=null) try{out.close();}catch(IOException e){}
        }
        
    }
}

⌨️ 快捷键说明

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