纳金网

标题: 读写TXT或者ini文件 [打印本页]

作者: may    时间: 2015-9-26 00:07
标题: 读写TXT或者ini文件
  1. //config.ini放在打包后的exe的同级文件夹
  2.     string DoneExePath()
  3.     {
  4.         string dpath = Application.dataPath;
  5.         int num = dpath.LastIndexOf("/");
  6.         dpath = dpath.Substring(0, num);
  7.         string url = dpath + "/config.ini";
  8.         string text = ReadFile(url, 2);
  9.         return text;
  10.     }


  11.     //config.ini放在打包后的_data文件夹
  12.     string DoneDataPath()
  13.     {
  14.         string dpath = Application.dataPath;
  15.         string url = dpath + "/config.ini";
  16.         string text = ReadFile(url, 2);
  17.         return text;
  18.     }

  19.     string ReadFile(string filePath, int lineNumber)
  20.     {
  21.         string[] strs = File.ReadAllLines(filePath);
  22.         if (lineNumber == 0)
  23.         {
  24.             return "";
  25.         }
  26.         else if (lineNumber <= strs.Length)
  27.         {
  28.             return strs[lineNumber - 1];
  29.         }
  30.         else
  31.         {
  32.             Debug.LogWarning("your lineNumber out of text row counts!");
  33.             return "";
  34.         }
  35.     }
复制代码





欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5