它工作正常,但我需要逐行写入数据。我从 arraylis 对象中获取一个数据,并希望将信号线写入文本文件。第二个对象应该在下一行。
public void writeFile() {
FileWriter writer = null;
try {
writer = new FileWriter("E:/AutomationToolWorkplace/AutomationTool/Test/ExpectedOutputHomescreenModule1.txt");
for (String str : MP_result_set) {
System.out.println("");
writer.write(str);
}
writer.close();
} catch (IOException ex) {
Logger.getLogger(Transciever.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
writer.close();
} catch (IOException ex) {
Logger.getLogger(Transciever.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
输出:
{"data":
{"shared":false,
"port":"4096",
"packageName":"",
"installed":false,
"lock":false,
"like":false,
"type":"HomeScreen",
"ip":"192.168.1.24",
"screenId":"9999",
"selected":false,
"category":"",
"servicetype":"",
"price":"",
"subscribe":false,
"event":false,
"subtype":"Recommended",
"predefined":false,
"pricingmodel":"PPC",
"packageSelected":false}}
{"data":{
"port":"4096",
"screenId":"2050",
"result":"failure",
"recordList":[],
"reminderList":[],
"msg":"No record",
"playList":[],
"ip":"192.168.1.24"}}
{"data":{
"port":"4096",
"screenId":"12105",
"result":"success",
"list":["music","Action","Romance","Horror","Comedy","Thriller","Mystery","Drama"],
"type":"genre",
"ip":"192.168.1.24"}}