SpringBoot读取Linux服务器某路径下文件读取项目Resource下文件
// SpringBoot读取Linux服务器某路径下文件public String messageToRouted() { File file = null; try { file = ResourceUtils.getFile("/home/admin/logs/test/routed.txt"); // 获取文件输入流 InputStream inputStream = new FileInputStream(file); List<String> fileList = IOUtils.readLines(inputStream); log.info("fileList:{}", fileList); fileList.forEach(rd -> { RoutedPO routedPO = new RoutedPO(); routedPO.setFulfillmentOrderName(rd.trim()); routedPO.setRoutedTo("test"); // 通知分单结果 routedService.notifyRoutedResult(routedPO, OfcRoutedOperate.INSERT); }); } catch (FileNotFoundException e) { log.info("文件不存在!"); return "文件不存在!"; } catch (IOException e) { log.info("文件读取异常!"); return "文件读取异常!"; } return "success!"; }
// SpringBoot读取Resource下文件public String messageToRouted(){ try { ClassPathResource classPathResource = new ClassPathResource("routed.txt"); // 判断文件是否存在 boolean exists = classPathResource.exists(); if(!exists){ log.info("文件不存在!"); return "文件不存在!"; } try { // 获取文件输入流 InputStream inputStream = classPathResource.getInputStream(); List<String> fileList = IOUtils.readLines(inputStream); log.info("fileList:{}",fileList); fileList.forEach(rd ->{ RoutedPO routedPO = new RoutedPO(); routedPO.setFulfillmentOrderName(rd.trim()); routedPO.setRoutedTo("test"); // 通知分单结果 routedService.notifyRoutedResult(routedPO, OfcRoutedOperate.INSERT); }); } catch (IOException e) { log.info(e.getMessage()); } } catch (RuntimeException e) { log.info(e.getMessage()); } return "success!"; }
相关推荐
bluecarrot 2020-11-23
Attend 2020-11-17
ZHAICAN 2020-11-16
codedecode 2020-11-14
zhangbingb 2020-11-12
ykmail 2020-11-11
futurezone 2020-11-06
rikeyone 2020-11-04
橄榄 2020-11-04
WenCoo 2020-10-31
liuyuchen 2020-10-27
ROES 2020-10-24
Gexrior 2020-10-22
ZHAICAN 2020-10-20
风语者 2020-10-16
zhongguomin 2020-10-16
净无邪 2020-10-15