`
aijun980204
  • 浏览: 95813 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

U3D中的信息保存到外部的文件中

阅读更多
c#代码:
using System.Collections;
using System.IO;

public class FileIO
{
   public static bool WriteStringToFile(string filePath, string data, bool append)
   {
      try
      {
         StreamWriter sw = new StreamWriter(filePath, append);

         sw.Write(data);
         sw.Close();
         return true;
      }
      catch (System.Exception err)
      {
         return false;
      }
   }

   // Reads each line of a text file to a separate string which is stored
   // in an ArrayList and returned.
   public static ArrayList ReadFileToStrings(string filePath)
   {
      ArrayList list = new ArrayList();
      string line;

      // Read a file
      try
      {
         StreamReader sr = new StreamReader(filePath);

         line = sr.ReadLine();
         if (line != null)
            list.Add(string.Copy(line));

         while (line != null)
         {
            line = sr.ReadLine();
            if (line != null)
               list.Add(string.Copy(line));
         }

         sr.Close();

         return list;
      }
      catch (System.Exception err)
      {
         return list;
      }
   }
}

js代码:

import System.IO;

static function WriteStringToFile (filePath : String, data : String, append : boolean) : boolean {
   try {
      var sw = new StreamWriter(filePath, append);
     
      sw.Write(data);
      sw.Close();
      return true;
   }
   catch (err) {
      return false;
   }
}

// Reads each line of a text file to a separate string which is stored
// in an array and returned.
function ReadFileToStrings (filePath : String) : Array {
   var list = new Array();
  
   // Read a file
   try {
      var sr = new StreamReader(filePath);
     
      var line = sr.ReadLine();
  
      while (line != null) {
         list.Add(line);
         line = sr.ReadLine();
      }
     
      sr.Close();
      return list;
   }
   catch (err) {
      return list;
   }
}

引用位置:
http://forum.unity3d.com/viewtopic.php?t=15196&postdays=0&postorder=asc&start=0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics