用java来复制一张照片或者文档(用字节流)

 
 
package com.JavaIO;
//利用字节流来复制一张照片或者文档word
import java.io.*;

public class Copy2 {
	public static void copystream(String sf,String of)throws IOException {
		File f1=new File(sf);
		FileInputStream fin=new FileInputStream(f1);
		FileOutputStream fout=new FileOutputStream(new File(of));
		int len;
		byte[]b=new byte[1024];
		while((len=fin.read(b))!=-1) {
			fout.write(b);
		}
		fin.close();//承担有flush(刷新)功能
		fout.close();//同上
	}
	public static void main(String[] args) {
		String s1="E:\\福建师范大学@学习\\大一\\Java\\实验3 类与对象.docx";
		String s2="E:\\福建师范大学@学习\\大一\\Java\\实验3 类与对象2.docx";
		try {
			copystream(s1,s2);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	

}


猜你喜欢

转载自blog.csdn.net/weixin_41060905/article/details/80112650
今日推荐