我不明白这是怎么回事:
构造函数:
IsolatedStorageFile isf;
public FileManagement()
{
isf = IsolatedStorageFile.GetUserStoreForApplication();
}当我保存文件时:
public bool saveCredentials(String username, String userpass)
{
bool res = false;
StreamWriter writeFile = new StreamWriter(new IsolatedStorageFileStream("usercred.custom",
FileMode.Create, FileAccess.Write, isf));
writeFile.WriteLine(username);
writeFile.WriteLine(userpass);
res = true;
return res;
}当我试着读它们的时候:
public String readUsername()
{
String username = "";
IsolatedStorageFileStream fileStream = isf.OpenFile("usercred.custom", FileMode.Open, FileAccess.Read);
StreamReader reader = new StreamReader(fileStream);
username = reader.ReadLine();
return username;
}读取返回null。
我尝试保存一个文件并将一些内容写入其中,但不知何故不起作用。
发布于 2012-09-19 23:45:06
你必须关闭你的流。请在返回前添加reader.Close()、writefile.Close()和fileStream.Close(),然后重试。
https://stackoverflow.com/questions/12497588
复制相似问题