java: file/outputStream/InputStream 复制文件

java i/o 复制文件

public static void main(String[] args) throws Exception {
		// TODO 自动生成的方法存根
		
		if(args.length != 2)
		{
			System.out.println("您输入的参数有误");
			System.exit(1);
		}
		
		if(args[0].equals(args[1]))
		{
			System.out.println("源文件和目标文件不能一致");
			System.exit(2);
		}
		
		File file = new File(args[0]);
		if(file.exists())
		{
			InputStream ipt = new FileInputStream(file);
			File file2 = new File(args[1]);
			OutputStream out = new FileOutputStream(file2);
			int temp = -1;
			while( (temp = ipt.read())!=-1 )
			{
				out.write(temp);
			}
			System.out.println("文件复制成功");
			ipt.close();
			out.close();
			
		}else{
			System.out.println("源文件不存在");
			System.exit(3);
		}

	}

  

原文地址:https://www.cnblogs.com/achengmu/p/7119380.html