0
我只是想用一些基本的獨立存儲功能,並且我一直在這條線讓我保存數據功能的無效操作:獨立存儲問題WP7
IsolatedStorageFileStream fs = savegameStorage.OpenFile(Filename, FileMode.Open);
這裏是我的兩個主要功能與...合作。
public static void OpenData()
{
IsolatedStorageFile savegameStorage = IsolatedStorageFile.GetUserStoreForApplication();
if (savegameStorage.FileExists(Filename))
{
using (IsolatedStorageFileStream fs = savegameStorage.OpenFile(Filename, System.IO.FileMode.Open))
{
if (fs != null)
{
if (fs.Length == 0)
{
fs.Close();
fs.Dispose();
SaveData();
return;
}
// Reload the saved high-score data.
byte[] saveBytes = new byte[6 * (50)];
int count = fs.Read(saveBytes, 0, (6 * 50) + 8);
ByteStream BS = new ByteStream(ByteStreamMode.Read, saveBytes, 0);
LevelData.LastStage = BS.ReadInt32();
LevelData.LastLevel = BS.ReadInt32();
for (int i = 0; i < 6; ++i)
for (int x = 0; x < 5; ++x)
for (int y = 0; y < 10; ++y)
LevelData.LevelComplete[i][x, y] = BS.ReadBool();
}
else
{
fs.Close();
fs.Dispose();
savegameStorage.CreateFile(Filename);
SaveData();
}
fs.Close();
}
}
else
{
SaveData();
}
}
public static void SaveData()
{
IsolatedStorageFile savegameStorage = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream fs = savegameStorage.OpenFile(Filename, FileMode.Open);
if (fs != null)
{
ByteStream BS = new ByteStream(ByteStreamMode.Write, null, 0);
BS.WriteInt32(LevelData.LastStage);
BS.WriteInt32(LevelData.LastLevel);
for (int i = 0; i < 6; ++i)
for (int x = 0; x < 5; ++x)
for (int y = 0; y < 10; ++y)
BS.WriteBool(LevelData.LevelComplete[i][x, y]);
fs.Write(BS.StreamBuffer, 0, BS.StreamBuffer.Length);
}
fs.Close();
}
您是否嘗試過創建較小的文件?可能是文件沒有足夠的空間。如果你需要更多的空間,你必須要求它。 – ChrisF