java读取resources文件

2016-05-25  本文已影响723人  jacksu在简书
    String str = ReadFile.read(getClass().getResourceAsStream("sence/"+file));
    public static String read(InputStream inputStream) {
        BufferedReader reader = null;
        String laststr = "";
        try{

            InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
            reader = new BufferedReader(inputStreamReader);
            String tempString = null;
            while((tempString = reader.readLine()) != null){
                laststr += tempString;
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            if(reader != null){
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return laststr;
    }
上一篇下一篇

猜你喜欢

热点阅读