注意: 字符流只能处理文本文件,字节流可以处理非文本文件,也可复制文本文件的复制,其他操作可能会出现乱码。
说明:
文本文件:.txt、.java、.c、.cpp、.py等
非文本文件:.doc、.xls、.jpg、.pdf、.mp3、.mp4、.avi 等
File file = new File("face.png");
File newFile = new File("face_copy.png");
FileInputStream fis=new FileInputStream(file);
FileOutputStream fos=new FileOutputStream(newFile);
byte[] cBuffer = new byte[5];
int len;
while((len=fis.read(cBuffer))!=-1){
fos.write(cBuffer);
}
fos.close();
fis.close();
/**
* 需求复制face.png为face_copy.png
*/
@Test
public void test01(){
File file =null;
File newFile=null;
FileInputStream fis=null;
FileOutputStream fos=null;
try {
file = new File("face.png");
newFile = new File("face_copy.png");
fis = new FileInputStream(file);
fos = new FileOutputStream(newFile);
byte[] cBuffer = new byte[5];
int len;
while((len=fis.read(cBuffer))!=-1){
fos.write(cBuffer);
}
System.out.println("复制成功");
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
try {
if (fos!=null){
fos.close();
}
if (fis!=null){
fis.close();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
推荐阅读:
vue.js:634 [Vue warn]: Property or method "userName" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See:
状态码:415,发送HTTP请求返回415状态码的解决办法
SpringBoot 整合 webapp时 访问404的解决办法
Vue 打开页面时就加载方法,例如查询
SpringCloud怎么调用多个服务的信息
Spring整合Mybatis
SpringCloud 加入 thymleaf前端页面的方法
Controller之间的跳转
Spring AOP的实现原理
This may be the result of an unspecified view, due to default view name generation
行动消除疑虑