序列化
将对象转换为可存储或可传输的字节流或其他数据格式的过程。
依赖FastJSON的序列化(序列化为JSON)
public static void main(String[] args) throws Exception {
User user = new User();
user.setAge(18);
user.setUserName("张三");
String jsonString = JSONObject.toJSONString(user);
File file = new File("user.json");
Files.write(file.toPath(), jsonString.getBytes(StandardCharsets.UTF_8));
System.out.println(file.length());
}
2025/12/16大约 1 分钟
