我收到以下共享冲突:
System.IO.IOException: 'Sharing violation on path /data/user/0/android_game.android_game/files/GameSave.txt'在尝试使用Visual Studio写入/读取Environment.SpecialFolder.Personal目录中的文件时,请执行以下代码
string FilePath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
FilePath = Path.Combine(FilePath, "GameSave.txt");
StreamWriter savefile = new StreamWriter(FilePath, true);
savefile.WriteLine("test");
StreamReader sr = new StreamReader(FilePath);
Console.WriteLine(sr.ReadLine());
sr.Close();对于上下文,我只需要一个游戏的基本文本保存文件,我不是试图与其他应用程序共享。欢迎任何帮助,谢谢。
发布于 2020-01-03 17:54:15
找到这个帖子后就明白了:Sharing violation IOException while reading and writing to file C#
解决方案是在使用savefile.Close()读取文件之前关闭流编写器
https://stackoverflow.com/questions/59562067
复制相似问题