【发布时间】:2017-05-22 16:56:25
【问题描述】:
我正在将 BLE 扫描结果写入 CSV 文件。我目前正在做的是将所有数据写在另一个之下。 数据由设备名称、rssi 和 mac 地址组成。例如,CSV 文件如下所示 -
DeviceA -85 DS:DA:AB:2B:B4:AE
DeviceB -100 2C:18:0B:2B:96:9E
DeviceA -85 DS:DA:AB:2B:B4:AE
我的要求是这样写 -
DeviceA -85 DS:DA:AB:2B:B4:AE DeviceB -100 2C:18:0B:2B:96:9E
DeviceA -85 DS:DA:AB:2B:B4:AE
在设备 A 的最后一列之后,我需要从设备 B 的新列开始,而不是写在设备 A 下方。 同样对于设备 C,我想把它写在设备 C 旁边......等等。这是我写入 CSV 的代码。
public final String DATA_SEPARATOR = ",";
public final String LINE_SEPARATOR = System
.getProperty("line.separator");
try {
fileName = "test.csv";
path = Environment.getExternalStorageDirectory()
+ File.separator + "Documents";
path += File.separatorChar + "SampleApp";
File file = new File(path, fileName);
new File(path).mkdirs();
file.createNewFile();
fileStream = new OutputStreamWriter(new FileOutputStream(file));
fileStream.write("sep= " + DATA_SEPARATOR + LINE_SEPARATOR);
} catch (IOException e) {
e.printStackTrace();
fileStream = null;
}
private void writeElements(Object... elements) throws IOException {
if (fileStream != null) {
for (Object o : elements) {
fileStream.write(o.toString());
fileStream.write(DATA_SEPARATOR);
}
fileStream.write(LINE_SEPARATOR);
}
}
writeElements(btDeviceName, btRSSIValue, btMacId) 不时被bluetoothScan() 方法调用。
我怎样才能在旁边实现写作?
【问题讨论】: