package com.qiwu.chatbotbackend.GameEnvironment; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; public class Util { public static String getJsonString(String fullName) { Reader reader = null; String jsonString = ""; try { // System.out.println("以字符为单位读取文件内容,一次读多个字节:"); // 一次读多个字符 char[] tempchars = new char[256]; int charread = 0; reader = new InputStreamReader(new FileInputStream(fullName)); // 读入多个字符到字符数组中,charread为一次读取字符数 while ((charread = reader.read(tempchars)) != -1) { // 同样屏蔽掉\r不显示 if ((charread == tempchars.length) && (tempchars[tempchars.length - 1] != '\r')) { // System.out.println(tempchars); jsonString = jsonString + String.valueOf(tempchars); // System.out.print(tempchars); } else { for (int i = 0; i < charread; i++) { if (tempchars[i] == '\r') { continue; } else { jsonString = jsonString+tempchars[i]; // System.out.print(tempchars[i]); } } } } } catch (Exception e1) { e1.printStackTrace(); } finally { if (reader != null) { try { reader.close(); } catch (IOException e1) { } } } return jsonString; } }