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

2017-08-16  本文已影响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();
    }

上一篇下一篇

猜你喜欢

热点阅读