Java实现一行一行读取文件内容(进行编码处理)

    
// 读取文件内容
public String readFile(){ String path = ""; File file = new File(path); StringBuilder result = new StringBuilder(); try{ BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));//构造一个BufferedReader类来读取文件 String s = null; while((s = br.readLine())!=null){//使用readLine方法,一次读一行 result.append( System.lineSeparator() + s); } br.close(); }catch(Exception e){ e.printStackTrace(); } return result.toString(); }

 

posted @ 2019-06-06 13:03  追梦滴小蜗牛  阅读(28603)  评论(0编辑  收藏  举报