Process需要注意的地方

本文介绍了一种从指定路径下载文件并进行处理的方法。通过使用Java编程语言,文章详细展示了如何通过运行Linux命令来复制文件,并将其下载到客户端的过程。此外,还涉及到了临时文件的管理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

try {
String [] filePathSplit = filePath.split("/");
String dictCode="FilePathFromTBPM";
ListDictByCodePo listDictByCodePo = new ListDictByCodePo();
listDictByCodePo.setDictCode(dictCode);
BaseResult<SysDictVo> sysDictVoResult = fileCenterService.listDictByCode(listDictByCodePo);
String configPath = sysDictVoResult.getData().getPath();
log.info("配置的TBPM文件路径:"+configPath);
String fileName = System.currentTimeMillis()+"."+fileType;
String tempPath = "/home/SiteSelection/Temp/";
String downLoadPath = tempPath+fileName;
// 文件完整路径
String fullPath = configPath.concat("/").concat(filePath);
//cp命令复制文件
log.info("复制文件开始");
Process process =null;
String cpCommand = "cp " +" "+ fullPath+" "+downLoadPath;
    process = Runtime.getRuntime().exec(cpCommand);
    log.info(IOUtils.toString(process.getInputStream()));//坑点:这个加入的作用相当于 在linux命令行敲入回车键
    process.destroy();
    log.info("复制文件结束");
log.info("开始下载附件文件: " + downLoadPath);
long start = System.currentTimeMillis();
PhotoUtil.downloadPhoto(downLoadPath, response,fileName);
log.info("附件文件: " + downLoadPath + " 下载完成, 耗时: " + (System.currentTimeMillis() - start));
log.info("获取附件文件请求结束");
//删除临时文件
log.info("删除文件开始");
FileUtils.forceDelete(new File(downLoadPath));
    log.info("删除文件结束");
} catch (Exception e) {
log.error("获取附件文件失败:" + e.getMessage(), e);
throw new Exception("获取附件文件失败!");
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值