Unity讀取Json和txt檔案操作

2021-09-28 22:52:49 字數 1011 閱讀 2518

自己寫了一些載入json和讀取txt檔案的小方法,基本都是讀取很容易的,因為發現每次訪問什麼我都得自己重新再想在寫好麻煩啊,在這記下來以後省事哈哈哈

using system.io;

using system.text;

using unityengine;

public static class jsontool

} }public static t loadjsondata(string jsontext)

/// /// 尋找streamingassets下的json檔案

///

///

///

public static string readjsontext(string name)

}}}

using system.io;

public static class txttool

} }/// /// 讀取文字的某一行,從1開始讀(第一行rownum就寫1)

///

///

///

public static string readtextrow(string path,int rownum)

return string.empty;

}} }

}

/// /// 讀取excel

///

///

///

public static dataset loadexceltodataset(string path)

else if (extension == ".xlsx")

else if (extension == ".csv")

if (reader == null)

return null;

using (reader)

});}

return ds;

}}

讀取TXT配置檔案 非unity

streamreader類的方法不是靜態方法,所以要使用該類讀取檔案首先要例項化該類,在例項化時,要提供讀取檔案的路徑。我在這把檔案放在了bin目錄下,所以路徑不用寫全,很簡單,基本就是切割再切割 為了省事,我把文字寫成了這樣,冒號前面是名字什麼的,後面是具體數值 streamreader sr f...

讀取excel和txt資料

1.建立乙個file檔案物件 並獲取資料 file file new file 檔案絕對位置 包含檔名和檔案字尾 2.建立乙個excel物件 workbook wb workbook.getworkbook file 3.獲取excel每頁的資訊 乙個excel 中可以有很多頁,在excel下方切換...

java讀取和寫入txt檔案

要處理的資料為以下資料,需要將資料中的 以及 全部變成tab空格 1 rhizoma polygoni cuspidati hu zhang 虎杖 cyp1b1 2 rhizoma polygoni cuspidati hu zhang 虎杖 hgf hpta 3 rhizoma polygoni ...