首页 > 代码库 > Java 拷贝文件内容

Java 拷贝文件内容

说明:

把d盘下a.txt 中的内容复制到e盘下e.txt文件中

	private static void copyDataBase() {
		try {
			File f1 = new File("d:/a.txt");
			File f2 = new File("e:/e.txt");
			InputStream in = new FileInputStream(f1);

			OutputStream out = new FileOutputStream(f2);

			byte[] buf = new byte[1024];
			int len;
			while ((len = in.read(buf)) > 0) {
				out.write(buf, 0, len);
			}
			in.close();
			out.close();
			System.out.println("File copied.");
		} catch (FileNotFoundException ex) {
			System.out.println(ex.getMessage() + " in the specified directory.");
			System.exit(0);
		} catch (IOException e) {
			System.out.println(e.getMessage());
		}
	}


Java 拷贝文件内容