zoukankan      html  css  js  c++  java
  • 读写Json创建删除文件夹

    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<T> JsonRead<T>(ref T tmp, string Path)
        {
            //    Resourcesconservation mRe;
            string[] mGroup;
            StreamReader stream = new StreamReader(Path);
            mGroup = stream.ReadToEnd().Split('
    ');
            List<T> tmps = new List<T>();
            for (int i = 0; i < mGroup.Length - 1; i++)
            {
    
                tmps.Add(JsonUtility.FromJson<T>(mGroup[i]));
            }
            CloseRead(stream);
            return tmps;
    
        }
        //写入Json
        public static void JsonWrite<T>(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<string> GetDirs(string dirPath) { List<string> nameArray = new List<string>(); 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; } /// <summary> /// 检查路径下是否存在文件 /// </summary> /// <param name="Path"></param> /// <returns></returns> 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); } }
  • 相关阅读:
    第三方网站实现绑定微信登陆
    安卓微信中bootstrap下拉菜单无法正常工作的解决方案
    一个Web钢琴谱记忆工具
    腾讯实习生面试经历-15年3月-Web前端岗
    AngularJS自定义指令三种scope
    AngularJS在自定义指令中传递Model
    Canvas文本绘制的浏览器差异
    AngularJS学习笔记
    善用width:auto以及white-space:nowrap以防止布局被打破
    Timeline中frame mode帧模式中idle占据大片位置
  • 原文地址:https://www.cnblogs.com/SevenPixels/p/10911665.html
Copyright © 2011-2022 走看看