我有一个FileOutputStream
和一个这样的圈子:
PrintStream output = new PrintStream(new FileOutputStream("XXXX.json"));
output.print("{\"ObjectsList\": [");
for (int i = 0; i < something.length; i++) {
output.print("{"AAAA"},");
}
output.print("]}")
但在char ","
output.print("]}");
如何在EOF-1或EOF-2上写下来覆盖最后一个字符","
答案 0 :(得分:2)
在something.length - 1
处停止循环,并使用output.print("{ AAAA"}");
答案 1 :(得分:0)
String var = "";
var = "{\"ObjectsList\": [";
for (int i = 0; i < something.length; i++) {
var = "{"AAAA"},";
}
//var.substring(0, var.length()-1) => remove the last char
output.print(var.substring(0, var.length()-1) + "]}");
答案 2 :(得分:0)
尝试这样的事情:
output.println("{\" ObjectsList \": [");
for(int i=0;i<something.length;i++){
String out="{\""+i+"}";
if(i!=something.length-1 ){
out+=", ";
}
output.println(out);
}
output.print("]}");