"设备尚未就绪"撰写或阅读文件时

时间:2017-02-14 08:57:12

标签: c# .net

当我尝试打开文件时,总会出现异常" System.IO.IOException:'设备尚未就绪。"出现:

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

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

我的堆栈跟踪没有提供任何有意义的消息:

  

发生了System.IO.IOException         的HResult = 0x80070015
        消息=设备尚未就绪。

     

源= mscorlib程序
        堆栈跟踪:
         在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)
         在System.IO.StreamReader..ctor(String path,Encoding encoding,Boolean detectEncodingFromByteOrderMarks,Int32 bufferSize,Boolean checkHost)
         在System.IO.File.InternalReadAllText(String path,Encoding encoding,Boolean checkHost)
         在System.IO.File.ReadAllText(String path)          at [..]。[..] \ Program.cs中的Main(String [] args):line [..]

0 个答案:

没有答案