java自用代码(包括:新建单线程、创建文件夹及文件、map转为json并将json写入txt、文件剪切或改名)...
生活随笔
收集整理的这篇文章主要介绍了
java自用代码(包括:新建单线程、创建文件夹及文件、map转为json并将json写入txt、文件剪切或改名)...
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
// 单向光闸写入文件线程new Thread(new Runnable() {// 将map转为jsonJSONObject obdjson = new JSONObject(data);@Overridepublic 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();
转载于:https://www.cnblogs.com/ITzhangda/p/10238063.html
总结
以上是生活随笔为你收集整理的java自用代码(包括:新建单线程、创建文件夹及文件、map转为json并将json写入txt、文件剪切或改名)...的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 5 LInux系统目录结构
- 下一篇: 网络版ATM项目的实现——客户端