当前位置 : 主页 > 编程语言 > java >

简易的文件拷贝

来源:互联网 收集:自由互联 发布时间:2021-06-28
CopyFileDemo.java package file_Stream;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;public class CopyFileDemo {private static String str;public static void main(String[] args)
CopyFileDemo.java
package file_Stream;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class CopyFileDemo {
	private static String str;

	public static void main(String[] args) throws Exception {
		in();
		out();

	}

	public static void in() throws IOException {
		File f = new File("file/BoyNextDoor.txt");
		FileInputStream in = new FileInputStream(f);
		byte[] buffer = new byte[1024];
		int len = -1;
		while ((len = in.read(buffer)) != -1) {
			str = new String(buffer, 0, len);
			System.out.println(str);
		}
		in.close();
	}

	public static void out() throws Exception {

		File ff = new File("file/zxf.txt");
		FileOutputStream out = new FileOutputStream(ff, true);
		out.write(str.getBytes());
		out.close();
	}
}
网友评论