zoukankan      html  css  js  c++  java
  • 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!"; }
  • 相关阅读:
    2822 爱在心中
    P1707 刷题比赛
    1269 匈牙利游戏
    1482 路线统计
    Codevs 1287 矩阵乘法&&Noi.cn 09:矩阵乘法(矩阵乘法练手题)
    P2022 有趣的数
    1087 麦森数
    P1111 修复公路
    python为在线漫画站点自制非官方API(未完待续)
    逻辑运算0==x和x==0具体解释
  • 原文地址:https://www.cnblogs.com/thiaoqueen/p/11848651.html
Copyright © 2011-2022 走看看