// 单向光闸写入文件线程
new Thread(new Runnable() {
// 将map转为json
JSONObject obdjson = new JSONObject(data);
@Override
public void run() {
try {
//创建文件夹及文件
String fileName = UUID.randomUUID().toString().replaceAll("-", "");
String wfileName = "c:\\外网\\"+fileName+".obd";
String path = "E:\\test\\"+fileName+".temp";
File fpath = new File(path);
File parentFile = fpath.getParentFile();
if(!parentFile.exists())
{
parentFile.mkdirs();
}
fpath.createNewFile();
// 将json写入到txt中
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path, true)));
out.write(obdjson.toJSONString());
out.close();
//剪切并重命名
fpath.renameTo(new File(wfileName));
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();