adressmoeistranici
@adressmoeistranici
Делатель

Как избежать ошибку IOException?

IOException: Sharing violation on path C:\Users\Дмитрий Королев\Documents\Editor Music Player\Assets\Editor Music Player\Data\trackList.txt
System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/FileStream.cs:320)
System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share)
(wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
System.IO.StreamWriter..ctor (System.String path, Boolean append, System.Text.Encoding encoding, Int32 bufferSize) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/StreamWriter.cs:124)
System.IO.StreamWriter..ctor (System.String path)
(wrapper remoting-invoke-with-check) System.IO.StreamWriter:.ctor (string)
System.IO.File.WriteAllLines (System.String path, System.String[] contents) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/File.cs:601)
PlayerWindow.WriteLineList (System.String[] dir) (at Assets/Editor Music Player/PlayerWindow.cs:120)
PlayerWindow.ReadDirectory () (at Assets/Editor Music Player/PlayerWindow.cs:108)
PlayerWindow.OnGUI () (at Assets/Editor Music Player/PlayerWindow.cs:253)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)

private void WriteLineList(params string[] dir)
{
if (!Directory.Exists("Assets/Editor Music Player/Data"))
Directory.CreateDirectory("Assets/Editor Music Player/Data");
if (!File.Exists("Assets/Editor Music Player/Data/trackList.txt"))
File.Create("Assets/Editor Music Player/Data/trackList.txt");
File.WriteAllLines("Assets/Editor Music Player/Data/trackList.txt", dir);
}
  • Вопрос задан
  • 1518 просмотров
Решения вопроса 1
@leremin
atypical programmer
try
{
if (!Directory.Exists("Assets/Editor Music Player/Data"))
Directory.CreateDirectory("Assets/Editor Music Player/Data");
if (!File.Exists("Assets/Editor Music Player/Data/trackList.txt"))
File.Create("Assets/Editor Music Player/Data/trackList.txt");
File.WriteAllLines("Assets/Editor Music Player/Data/trackList.txt", dir);
}
catch (IOException ex)
{
MessageBox.Show(ex.Message);
}
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы