查看: 793|回复: 0
打印 上一主题 下一主题

[其他] 读写TXT或者ini文件

[复制链接]
may    

8830

主题

81

听众

7万

积分

首席设计师

Rank: 8Rank: 8

纳金币
52352
精华
343

最佳新人 热心会员 灌水之王 活跃会员 突出贡献 荣誉管理 论坛元老

跳转到指定楼层
楼主
发表于 2015-9-26 00:07:13 |只看该作者 |倒序浏览
  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.     }
复制代码
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2025-7-26 14:11 , Processed in 0.060061 second(s), 29 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部