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;
}
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/java/278690.html