D
D
Dmitry Korolev2017-02-09 19:18:19
C++ / C#
Dmitry Korolev, 2017-02-09 19:18:19

How to avoid IOException error?

IOException: Sharing violation on path C:\Users\Dmitry Korolev\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);
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
leremin, 2017-02-09
@adressmoeistranici

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question