**
编程要求
**
请仔细阅读右侧代码,根据方法内的提示,在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就不能用了。