第4关:复制文件

**

编程要求

**
请仔细阅读右侧代码,根据方法内的提示,在Begin - End区域内进行代码补充,具体任务如下:

复制src/step4/input/目录下的input.txt文件到src/step4/output/目录下,新文件命名为output.txt;

复制src/step4/input/目录下的input.jpg文件到src/step4/output/目录下,新文件命名为output.jpg;

下面展示一些 内联代码片

public void task() throws IOException{
		/********* Begin *********/
			BufferedReader br=new BufferedReader(new FileReader("src/step4/input/input.txt"));
		BufferedWriter bw=new BufferedWriter(new FileWriter("src/step4/output/output.txt"));
		FileInputStream br1=new FileInputStream("src/step4/input/input.jpg");
		FileOutputStream bw1=new FileOutputStream("src/step4/output/output.jpg");
		byte[]b=new byte[1024];
		int len=0;
		String s="";
		while((s=br.readLine())!=null) {
			bw.write(s);
			bw.newLine();
		}
		br.close();
		bw.close();
		while((len=br1.read(b))!=-1) {
			bw1.write(b,0,len);
			
		}
		bw1.close();
		br1.close();
		
		
		/********* End *********/		
	}


字符流只适用于操作字符类型的文件,不能操作非字符类型的。我们需要使用字节流来操作非字符类文件,所以题中的.jpg文件需要使用字节流,这个时候BufferedReader就不能用了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值