@Data
public class Person implements Serializable {
private static final long serialVersionUID = -348549485910717452L;
private String name;
private String sex;
private Integer age;
}
3、讀取JSON文件獲取字符串
public static String readToString(String fileName) {
String encoding = "UTF-8";
File file = new File(fileName);
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);
} catch (UnsupportedEncodingException e) {
System.err.println("The OS does not support " + encoding);
e.printStackTrace();
return null;
}
}