在輸出中可以發現空值並不用理會,可以在需要資料時排除即可。
因為讀取檔案時僅能被一個檔案開啟,所以請不要把JS與C#的程式碼打勾以免錯誤!!
‧FileInfo = 檔案資訊。
‧StreamReader = 串流讀取器。
‧LineReader = 每次讀取一行。
@相關方法
ReadAllText = 一次把所有資料讀出。
using System.Collections;
using System;
using System.IO;
public class LineReader : MonoBehaviour
{
protected FileInfo theSourceFile = null;
protected StreamReader reader = null;
protected string text = " "; // assigned to allow first line to be read below
protected String[] oringinData =new String[10];
public String[] newData =new String[10];
protected char[] delimiterChars = { ','};
protected int i;
void Start () {
theSourceFile = new FileInfo ("Data.txt");
reader = theSourceFile.OpenText();
i=0;
}
void Update () {
if (text != null) {
text = reader.ReadLine();
oringinData[i]=text;
Debug.Log("oringinData:"+oringinData[i]);
i++;
}
}
}
結果
protected var theSourceFile;
protected var reader;
protected var text : String = " ";
protected var oringinData : String[] =new String[10];
protected var i : int ;
function Start () {
theSourceFile = System.IO.FileInfo("Data.txt");
reader = theSourceFile.OpenText();
i=0;
}
function Update () {
if (text != null) {
text = reader.ReadLine();
oringinData[i]=text;
Debug.Log("(JS)oringinData:"+oringinData[i]);
i++;
}
}
結果
檔案下載
0 ♥:
張貼留言