java笔记__读取文件内容
作者:互联网
public JSONObject toGetFileData(Integer model){ //用于存储文件内容 String jsonString = ""; InputStream is = null; try { is = new FileInputStream("D:\\data\\xxxxx.txt"); //用来保存每行读取的内容 String line = null; BufferedReader reader = new BufferedReader(new InputStreamReader(is)); //读取第一行 line = reader.readLine(); //如果line为空说明读完了 while (line != null) { //将读到的内容添加到 jsonString 中 jsonString += line; //添加换行符 jsonString += "\n"; //读取下一行 line = reader.readLine(); } reader.close(); is.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } JSONObject jsonObject = JSONObject.parseObject(jsonString); return jsonObject; }
标签:__,jsonString,java,读取,reader,new,line,null 来源: https://www.cnblogs.com/luyuting/p/16547295.html