private static final String PATH_PREFIX = System.getProperty("user.dir") + File.separator + "config/json/";
private JsonLoadUtils() {
}
public static String load(String fileName) throws IOException {
try {
File file = ResourceUtils.getFile(String.format("%s%s", PATH_PREFIX, fileName));
return FileUtils.readFileToString(file, "UTF-8");
} catch (Exception e) {
log.error("文件[{}]加载失败。", fileName, e.getMessage());
throw e;
}
}
/**
* 文件路径
* @param path
* @return
*/
public static Properties getProperty(String path) {
Properties properties = new Properties();
try {
properties.load(new InputStreamReader(new FileInputStream(path), "UTF-8"));
} catch (Exception e) {
log.error("read properties file Exception", e);
}
return properties;
}
/**
*
*@param filePath 读取文件路径
*@return: java.lang.String
*/
public static String readFile(String filePath) {
String fileContent = "";
try {
File f = new File(filePath);
if (f.isFile() && f.exists()) {
InputStreamReader read = new InputStreamReader(new FileInputStream(f), "UTF-8");
BufferedReader reader = new BufferedReader(read);
StringBuffer buffer = new StringBuffer();
String line;
while ((line = reader.readLine()) != null) {
buffer.append(line);
}
fileContent= buffer.toString();
read.close();
}
} catch (Exception e) {
System.out.println("读取文件内容操作出错");
e.printStackTrace();
}
return fileContent;
}