美文网首页
spring中手动获取classpath路径下的文件

spring中手动获取classpath路径下的文件

作者: 炫迈哥 | 来源:发表于2017-08-16 16:26 被阅读0次
    Resource[] resources = (Resource[]) resolver.getResources("classpath*:commonscripts/*.sh");
    for (Resource re : resources) {
        System.out.println(convertStreamToString(re.getInputStream()));
    }
    
    
    private static String convertStreamToString(InputStream is) {
    
            BufferedReader reader = new BufferedReader(new InputStreamReader(is));
            StringBuilder sb = new StringBuilder();
    
            String line = null;
            try {
                while ((line = reader.readLine()) != null) {
                    sb.append(line + "\n");
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return sb.toString();
        }
    
    

    相关文章

      网友评论

          本文标题:spring中手动获取classpath路径下的文件

          本文链接:https://www.haomeiwen.com/subject/wwgirxtx.html