我已經使用以下代碼進行文件讀取和寫入。iOS中的文件讀寫錯誤
private void StorePuzzleData()
{
FileInfo fileInfo = new FileInfo (Application.persistentDataPath + "\\" + difficultyLevel + puzzleId + ".txt");
if (fileInfo.Exists)
fileInfo.Delete();
string fileData = string.Empty;
foreach (CellInformation cellInfo in cellInfoList)
fileData += cellInfo.RowIndex + "#" + cellInfo.ColIndex + "#" + cellInfo.number + "#" + cellInfo.CellColor + "#" + cellInfo.CellDisplayColor + "#" + (cellInfo.IsGroupComplete ? 1 : 0) + ",";
StreamWriter streamWriter = fileInfo.CreateText();
streamWriter.WriteLine (fileData);
streamWriter.Close();
DataStorage.StorePuzzleTimePassed (difficultyLevel, puzzleId, GameController.gamePlayTime);
}
private void ReadPuzzleData()
{
// format: rownumber, colnumber, number, cellcolor, celldisplaycolor, isgroupcomplete
StreamReader streamReader = File.OpenText (Application.persistentDataPath + "\\" + difficultyLevel + puzzleId + ".txt");
string fileData = streamReader.ReadLine();
}
但是我在實際iOS設備運行中遇到了以下錯誤。此代碼在iMac以及Android設備中正確工作。
請給我一些建議什麼樣的變化,我需要做的,使這是正確的。
唯一不正確的是你的路徑中的最後一個斜槓是反斜槓,而所有其他斜槓都是正斜槓,請在代碼中的任何地方嘗試使用「//」而不是「\\」 –
然後它會在Windows上崩潰:) –