我尝试将csv文件转换为对象代表csv中的1行的对象的Json文件200K.
我在32位和Project配置VM参数上安装了Java: -Xmx1024m
但是我得到:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Unknown Source)
at java.lang.AbstractStringBuilder.expandCapacity(Unknown Source)
at java.lang.AbstractStringBuilder.ensureCapacityInternal(Unknown Source)
at java.lang.AbstractStringBuilder.append(Unknown Source)
at java.lang.StringBuffer.append(Unknown Source)
at java.io.StringWriter.write(Unknown Source)
at com.google.gson.stream.JsonWriter.string(JsonWriter.java:478)
at com.google.gson.stream.JsonWriter.value(JsonWriter.java:328)
at com.google.gson.Streams.write(Streams.java:113)
at com.google.gson.Streams.write(Streams.java:136)
at com.google.gson.Streams.write(Streams.java:136)
at com.google.gson.Streams.write(Streams.java:124)
at com.google.gson.Streams.write(Streams.java:136)
at com.google.gson.Gson.toJson(Gson.java:362)
at com.google.gson.Gson.toJson(Gson.java:346)
at com.google.gson.Gson.toJson(Gson.java:260)
at com.google.gson.Gson.toJson(Gson.java:240)
at ConvertFromCsv2JsonTWC.init(ConvertFromCsv2JsonTWC.java:186)
at ConvertFromCsv2JsonTWC.main(ConvertFromCsv2JsonTWC.java:48)
Run Code Online (Sandbox Code Playgroud)
在排队:
Gson gson = new Gson();
String output = gson.toJson(container);// <---- crash
Run Code Online (Sandbox Code Playgroud)
对于50k行,它工作正常.
这是Json I构建的模板:
{
"crs": {
"type": "none"
},
"type": "FeatureCollection",
"features": [{
"geometry": {
"type": "Point"
},
"properties": {
"ap mac": "00:11:22:33:44:55",
"ssid": "WiFi",
"lat": "35.111111",
"long": "-118.11111",
"address": "370 xxxxxx",
"city": "xxxxxxx",
"state": "CA",
"zip code": "11111",
"country": "US",
"business n": "",
"location c": "Health Club/Gym",
"location q": "",
"indoor fla": "yes"
},
"point": [35.390284,
-118.9929],
"id": 0,
"type": "Feature"
},
{...},
...
200000...
Run Code Online (Sandbox Code Playgroud)
所以我在properties列表中有200K对象
解决方法是创建每个20k的单独文件,但这不是好方法.
我怎么解决这个问题?
谢谢,
| 归档时间: |
|
| 查看次数: |
5610 次 |
| 最近记录: |