我在弄清楚如何将字符串拆分为多个文件时遇到问题。目前我应该得到两个包含 JSON 数据的文件。下面的代码写入第一个文件,但第二个为空。任何想法为什么?
public void splitFile(List<String> results) throws IOException {
int name = 0;
for (int i=0; i<results.size(); i ++) {
write = new FileWriter("/home/tom/files/"+ name +".json");
out = new BufferedWriter(write);
out.write(results.get(i));
if (results.get(i).startsWith("}")) {
name++;
}
}
}
编辑:它在开头的行拆分,{
因为这表示 JSON 文档的结尾。