You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.4 KiB

11 months ago
package com.dsideal.base.Util;
import com.alibaba.fastjson.JSONObject;
import java.io.*;
@SuppressWarnings("unchecked")
public class FileUtil {
/**
* JSONJSON
*
* :2018-12-12
* @param filePath
* @return
*/
public static JSONObject readJsonFile(String filePath)
{
String content=txt2String(new File(filePath));
return JSONObject.parseObject(content);
}
/**
*
*
* 2018-11-22
*
* @param file
* @return
*/
public static String txt2String(File file) {
String encoding = "UTF-8";
Long filelength = file.length();
byte[] filecontent = new byte[filelength.intValue()];
try {
FileInputStream in = new FileInputStream(file);
in.read(filecontent);
in.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
return new String(filecontent, encoding).replaceAll("\r", "");
} catch (UnsupportedEncodingException e) {
System.err.println("The OS does not support " + encoding);
e.printStackTrace();
return null;
}
}
}