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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值