zoukankan      html  css  js  c++  java
  • Java File 和 各种流

    1.Java读取File文件

    1.1读取相对路径下的file

    方式一:Spring 的 ResourceLoader:

        @Autowired
        private ResourceLoader resourceLoader;
    
      //path 为resources 文件
    public void initWorkFlow(String path) throws Exception { String line = null; { Resource workFlowResource = resourceLoader.getResource("classpath:"+path); BufferedReader brWorkFlow = new BufferedReader(new InputStreamReader(workFlowResource.getInputStream())); StringBuilder sb = new StringBuilder(); while ((line = brWorkFlow.readLine()) != null) { sb.append(line); } String result = sb.toString();   }

    方式二:用Java的Files和Paths:

        public void getPDDocument(String path) throws IOException {
            byte[] in = Files.readAllBytes(Paths.get(new File("").getAbsolutePath()+"/src/test/resources/"+path));
            String result = new String(in);
        }

    1.2

    1.3

    2.

    3.

    4.

  • 相关阅读:
    【统计学】第七章
    【统计学】第六章
    【统计学】第五章
    【统计学】第四章
    【统计学】第三章
    【统计学】第二章
    MYSQL基础
    股票数据Scrapy爬虫
    Scrapy爬虫基本使用
    Scrapy爬虫框架
  • 原文地址:https://www.cnblogs.com/kplsm123/p/9103682.html
Copyright © 2011-2022 走看看