码迷,mamicode.com
首页 > 编程语言 > 详细

SpringBoot读取Linux服务器某路径下文件\读取项目Resource下文件

时间:2019-11-13 14:39:47      阅读:905      评论:0      收藏:0      [点我收藏+]

标签:out   notify   sage   except   turn   col   stream   span   spring   

// 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!"; }

 

SpringBoot读取Linux服务器某路径下文件\读取项目Resource下文件

标签:out   notify   sage   except   turn   col   stream   span   spring   

原文地址:https://www.cnblogs.com/thiaoqueen/p/11848651.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!