import java.util.*;
import java.io.File;
import java.io.IOException;
import java.lang.String;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
public void writeCsvSortedTraceData(String filePath) {
FileOutputStream out = null;
OutputStreamWriter osw = null;
BufferedWriter bw = null;
try {
File finalCSVFile = new File(filePath);
out = new FileOutputStream(finalCSVFile);
osw = new OutputStreamWriter(out, "utf-8");
bw = new BufferedWriter(osw);
String title = "onlineUsrId" + ","+ "infectedUsrFlag" + "," + "sortedTraceInfo: [tslice cellId] ";
bw.append(title).append("\r");
for (int ueId : sortedTraceMap.keySet()) {
bw.append(ueId + ",");
if (infectedUserSet.contains(ueId)) {
bw.append("yes" + ",");
} else {
bw.append("no" + ",");
}
bw.append("[ ");
for (DualD data : sortedTraceMap.get(ueId)) {
bw.append("[ " + data.tSlice + " " + data.cellId+ " ]");
}
bw.append(" ]");
bw.append("\r");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bw != null) {
try {
bw.close();
bw = null;
} catch (IOException e) {
e.printStackTrace();
}
}
if (osw != null) {
try {
osw.close();
osw = null;
} catch (IOException e) {
e.printStackTrace();
}
}
if (out != null) {
try {
out.close();
out = null;
} catch (IOException e) {
e.printStackTrace();
}
}
}
System.out.println(filePath + " import succeed!");
}
java写CSV文件
最新推荐文章于 2024-01-27 08:00:00 发布