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

📄 safecopy.java

📁 java编程开发技巧与实例的编译测试通过的所有例程
💻 JAVA
字号:
import java.io.*;

public class SafeCopy
{
	public static void copyFile(DataInputStream in, DataOutputStream out) throws IOException
	{
		try
		{
			while (true)
				out.writeByte(in.readByte());
		}
		catch	(EOFException eof)
		{
			return;
		}
	}
	public static void main(String args[])
	{
		if (args.length != 2)
			System.out.println("Usage: java Copy sourceFile targetFile");
		else
		{
			String inFileName	=	args[0], outFileName = args[1];
			File inFile	=	new File(inFileName);
			File outFile	=	new File(outFileName);
			if (!inFile.exists())
				System.out.println(inFileName + " does not exist.");
			else if (outFile.exists())
				System.out.println(outFileName + " already exists");
			else
			{
				try
				{
					DataInputStream in	=	new DataInputStream(
												new BufferedInputStream(
													new FileInputStream(inFileName)));
					DataOutputStream out	=	new DataOutputStream(
							new BufferedOutputStream(
								new FileOutputStream(outFileName)));
					copyFile(in, out);
					in.close();
					out.close();
				}
				catch	(IOException ioe)
				{
					System.out.println("Unknown error: " + ioe);
				}
			}
		}
	}
}

⌨️ 快捷键说明

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