【问题标题】:System.IO.IOException: Sharing violation on pathSystem.IO.IOException:路径上的共享冲突
【发布时间】:2020-01-02 10:50:21
【问题描述】:

我收到以下共享违规:

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();

就上下文而言,我只需要一个游戏的基本文本保存文件,我不想与其他应用共享。欢迎任何帮助,谢谢。

【问题讨论】:

标签: c# android visual-studio xna monogame


【解决方案1】:

找到这个帖子后想通了:Sharing violation IOException while reading and writing to file C#

解决方案是在使用 savefile.Close() 读取文件之前关闭 Streamwriter

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-01
    相关资源
    最近更新 更多