博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
读写Json创建删除文件夹
阅读量:7237 次
发布时间:2019-06-29

本文共 2054 字,大约阅读时间需要 6 分钟。

using UnityEngine;using System.Collections;using System.Collections.Generic;using UnityEngine.UI;using System.IO;public static class Tools {  static   StreamWriter mStreamWriter;  static  StreamReader mStreamReader;  static   FileInfo file;    //读取Json    public static List
JsonRead
(ref T tmp, string Path) { // Resourcesconservation mRe; string[] mGroup; StreamReader stream = new StreamReader(Path); mGroup = stream.ReadToEnd().Split('\n'); List
tmps = new List
(); for (int i = 0; i < mGroup.Length - 1; i++) { tmps.Add(JsonUtility.FromJson
(mGroup[i])); } CloseRead(stream); return tmps; } //写入Json public static void JsonWrite
(ref T tmp, string Path) { Debug.Log(tmp + " " + Path); file = new FileInfo(Path); string json = JsonUtility.ToJson(tmp); mStreamWriter = file.CreateText(); mStreamWriter.WriteLine(json); Close(); } static void Close() { mStreamWriter.Close(); mStreamWriter.Dispose(); } static void CloseRead(StreamReader stream) { stream.Close(); stream.Dispose(); } //检查路径下是否有文件夹没有则创建 public static bool CheckDirectory( string UsePath) { if (!Directory.Exists(UsePath)) { Debug.Log("没有原始数据"); Directory.CreateDirectory(UsePath); return false; } else { return true; } } ///得到一个路径下的所有文件夹 public static List
GetDirs(string dirPath) { List
nameArray = new List
(); if (Directory.GetDirectories(dirPath).Length > 0) //遍历所有文件夹 { foreach (string path in Directory.GetDirectories(dirPath)) { // GetDirs(path, ref dirs); nameArray.Add(path.Substring(path.IndexOf("\\"))); } } return nameArray; } ///
/// 检查路径下是否存在文件 /// ///
///
public static bool CheckFile(string Path) { if (!File.Exists(Path)) { Debug.Log("没有原始数据"); File.Create(Path).Dispose(); return false; } else { return true; } } public static void DelDirectories(string Path) { Directory.Delete(Path, true); }}

 

转载于:https://www.cnblogs.com/SevenPixels/p/10911665.html

你可能感兴趣的文章
Lua中的require(转)
查看>>
软件工程
查看>>
CF451D Count Good Substrings (DP)
查看>>
centos7 VNC安装
查看>>
linux突然断电重启,配置文件丢失/程序无法打开/文件损坏
查看>>
static之静态初始化块
查看>>
[日常] Go语言圣经-Panic异常,Recover捕获异常习题
查看>>
Spring的测试
查看>>
WPF-禁止二次启动
查看>>
第2章
查看>>
ALV 选中后,点后退 SHORT DUMP 解决方法
查看>>
数据库分页【Limt与Limt..OFFSET 】
查看>>
2018-2019-1 20165206 《信息安全系统设计基础》第六周学习总结
查看>>
js中字符串全部替换
查看>>
关于linux安装时的分区
查看>>
Lesson 1#12 break 和 continue
查看>>
匿名方法
查看>>
10个调试技巧
查看>>
[转]JVM 堆内存设置原理
查看>>
(16)Spring Boot使用Druid(编程注入)【从零开始学Spring Boot】
查看>>