"The device is not ready" when writing or reading files

0

When I tried opening a file, there is always an exception "System.IO.IOException: 'The device is not ready." showing up:

// reading
var data = File.ReadAllText(@"D:\test.txt");

// writing
File.WriteAllText(@"D:\test.txt", "");

My stack trace doesn't give any meaningful message:

System.IO.IOException occurred
HResult=0x80070015
Message=The device is not ready.

Source=mscorlib
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean checkHost)
at System.IO.File.InternalReadAllText(String path, Encoding encoding, Boolean checkHost)
at System.IO.File.ReadAllText(String path) at [..].Main(String[] args) in [..]\Program.cs:line [..]

c#
.net
asked on Stack Overflow Feb 14, 2017 by MiP • edited Feb 14, 2017 by Mong Zhu

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0