package test.datatofile.easyjson;
import java.io.File;
import java.io.FileWriter;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSONWriter;
import xxx.DBHelper;
public class BigDataToFile {
public static DBHelper db = DBHelper.getInstance();
public static void main(String[] args) {
String sql = "select * from xxx a";
List<Map<String, Object>> list = db.queryForList(sql);
System.out.println(list.size());
File file = new File("C:\\Users\\asus\\Desktop\\test\\笔记\\java\\json\\file\\jsontest\\easyjson\\02.json");
if (file.exists()) {
file.delete();
}
try {
JSONWriter writer = new JSONWriter(new FileWriter(file));
writer.startArray();
int cnt = 0;
for (Map<String, Object> map : list) {
writer.writeObject(map);
cnt++;
if (cnt%10 == 0) {
System.out.println(cnt);
}
}
writer.endArray();
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}