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

📄 copy2.java

📁 java应用开发详解
💻 JAVA
字号:
import java.io.*;

public class Copy2 
{
    public static void main(String[] args) 
    {
	//用文件输入输出流代替
	FileInputStream in =null;
	FileOutputStream out =null;
	

	if(args.length !=2)
	{
		System.out.println("Usage:you must input the file path .");
		System.out.println("example: java Copy2 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 FileInputStream(inputFile);
        	out = new FileOutputStream(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 + -