【发布时间】:2018-10-11 22:04:01
【问题描述】:
我修改了我的代码:
private static final String SAMPLE_CSV_FILE_PATH = "src/main/resources/testCSV.csv";
private static final String OUT_PUT_CSV_PATH = "src/main/resources/outCSV.csv";
public static void main(String[] args) throws IOException {
Reader reader = Files.newBufferedReader(Paths.get(SAMPLE_CSV_FILE_PATH));
CSVReader csvReader = new CSVReader(reader);
List<String[]> records = csvReader.readAll();
Writer writer = Files.newBufferedWriter(Paths.get(OUT_PUT_CSV_PATH));
CSVWriter out = new CSVWriter(writer);
int i = 1;
int total = 0;
while(i < records.size()){
String[] result = records.get(i);
for(int j =1; j<= Integer.parseInt(result[1]); j++){
String pattern="00000";
DecimalFormat myFormatter = new DecimalFormat(pattern);
String output = myFormatter.format(j);
writer.append(result[0]+output+"\n");
total++;
}
i++;
}
out.flush();
out.close();
System.out.println(total);
}
现在我使用第一个 CSV 文件来生成序列号,类似于:
NAIS00001
NAIS00002
...
NAIS00625
然后我将这些序列号写入一个新的 CSV 文件。但是只有一列。一列中有 600 万条数据...如何为新列加注星标?
【问题讨论】:
-
"但是在json文件中写入太大了。" - 那是什么意思?你有错误吗?请提供更多详细信息。
-
或许您可以在此处编写 csv 示例,而不是链接外部服务。
标签: java json filewriter json-simple