标签:span ace ide rand 创建文件夹 dir 文件夹 txt ble
// 单向光闸写入文件线程 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();
java自用代码(包括:新建单线程、创建文件夹及文件、map转为json并将json写入txt、文件剪切或改名)
标签:span ace ide rand 创建文件夹 dir 文件夹 txt ble
原文地址:https://www.cnblogs.com/ITzhangda/p/10238063.html