文件的拷贝

文件的拷贝


//人员分站信息文件保存
public void saveRycz(String fileName) throws IOException {
log.error(“拷贝的文件路径为”+fileName);
String classPath = PersonStationParamServiceImpl.class.getResource("/").getPath();
//获取要复制的文件
File oldfile = new File(fileName);
//文件输入流,用于读取要复制的文件
FileInputStream fileInputStream = new FileInputStream(oldfile);
//要生成的新文件(指定路径如果没有则创建)
//File newfile = new File(classPath+"\errXml\errRYFZ.xml");
//String x= System.getProperty(“user.dir”)+ File.separator + “occouErr”+File.separator + UUID.randomUUID()+".xml";
//String x= Constant.BASE_UPLOAD_PATH + File.separator + “occouErr”+File.separator + UUID.randomUUID()+".xml";
//将当前目录下的文件全部保存到应用服务器
String path = Constant.BASE_UPLOAD_PATH + File.separator + “AllFile”;
File pathDir = new File(path);
//创建本地目录
if(!pathDir.exists()){
pathDir.mkdirs();
}
//log.error(“输出的文件路径为”+x);
//File newfile = new File(x);
/ //获取父目录
File fileParent = newfile.getParentFile();
System.out.println(fileParent);
//判断是否存在
if (!fileParent.exists()) {
// 创建父目录文件夹
fileParent.mkdirs();
}
//判断文件是否存在
if (!newfile.exists()) {
//创建文件
newfile.createNewFile();
}
/
log.error(“进入文件输出流”);
//新文件输出流
FileOutputStream fileOutputStream = new FileOutputStream(pathDir+File.separator + UUID.randomUUID()+".xml");
log.error(“输出的文件路径为”+pathDir+File.separator + UUID.randomUUID()+".xml");
byte[] buffer = new byte[1024];
int len;
//将文件流信息读取文件缓存区,如果读取结果不为-1就代表文件没有读取完毕,反之已经读取完毕
while ((len = fileInputStream.read(buffer)) != -1) {
fileOutputStream.write(buffer, 0, len);
fileOutputStream.flush();
}
fileInputStream.close();
fileOutputStream.close();
log.error(“拷贝成功”);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值