求助 不能实现复制功能

bluesky1986yang 2017-12-27 10:37:42
package copy;

import java.io.*;
public class copy {
public static void main(String[] args) throws IOException{
BufferedInputStream input1=new BufferedInputStream(new FileInputStream("D:/【03 编程兴趣】/1.txt"));
BufferedOutputStream output1=new BufferedOutputStream(new FileOutputStream("D:/【03 编程兴趣】/2.txt"));
int r;
while((r=input1.read())!=-1)
output1.write(r);
}
}

想将第一个文件1 的内容复制到文件2 实现不了 请问什么问题
...全文
132 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
自由自在_Yu 2017-12-28
  • 打赏
  • 举报
回复
public static void main(String[] args) throws IOException {
		BufferedInputStream input1 = new BufferedInputStream(
				new FileInputStream("D:/【03 编程兴趣】/1.txt"));
		OutputStream output1 = new FileOutputStream("D:/【03 编程兴趣】/2.txt");
		int r;
		byte[] buffer = new byte[1000];
		while ((r = input1.read(buffer, 0, 1000)) != -1) {
			System.out.println(new String(buffer));
			output1.write(buffer, 0, r);
		}
		
	}
自由自在_Yu 2017-12-28
  • 打赏
  • 举报
回复
BufferedOutputStream 是缓冲输出流。它继承于FilterOutputStream。 BufferedOutputStream 的作用是为另一个输出流提供“缓冲功能”。 1.txt复制过来的内容都保存在缓冲流中,刷新一下或者关闭流,就会把缓存区的内容复制到2.txt中 //output1.close(); output1.flush();

51,411

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧