- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
这一定是我见过的最奇怪的异常之一。使用File.WriteAllText静态方法写入文件时,不能写入特定文件名:“PRN”。你可以用一个简单的衬垫重新创建它:
File.WriteAllText("c:\\Temp\\PRN.txt", "write this to a file");
我尝试了不同的扩展,我尝试用这种方法写入不同的文件夹,但在所有情况下,当我尝试写入具有这个特定文件名的文件时,我都会遇到以下异常:
FileStream will not open Win32 devices such as disk partitions and tape drives. Avoid use of \"\\.\\" in the path.
堆栈跟踪如下所示:
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.StreamWriter.CreateFile(String path, Boolean append, Boolean checkHost)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost)
at System.IO.File.InternalWriteAllText(String path, String contents, Encoding encoding, Boolean checkHost)
at System.IO.File.WriteAllText(String path, String contents)
at WriteAllTextThrowsExceptionWithPRN.UnitTest1.TestMethod1() in c:\Users\ntregillus\Documents\Visual Studio 2013\Projects\WriteAllTextThrowsExceptionWithPRN\WriteAllTextThrowsExceptionWithPRN\UnitTest1.cs:line 14
知道为什么会发生这种情况吗?我想我要用我自己的文件编写器替换,但我发现文件名“PRD”会导致这个系统崩溃,这很疯狂。
最佳答案
关于c# - System.IO.File.WriteAllText 为特定文件名抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27306821/
File.WriteAllText 在每个字母和引号后插入一个空格。 例子: 原始文件 "JobID" "ParentJobID" 新建文件 " J o b I D " " P a r e n
我正在尝试将许多不同的表单保存到一个文本文件中,目前我有: 温度 风 下雨 云 我遇到的问题是它只保存“云”数据。有没有一种方法可以保存提交时的所有信息,并用逗号、破折号或空格将它们分隔开? 这是我目
我现在收到 3 份用户机器在使用我的软件时崩溃的报告。崩溃与我的程序无关,但当他们重新启动配置文件时,我的程序写入的所有文件都已损坏。 文件的写入方式没有什么特别之处,只需创建一个 Json 表示并使
假设我正在使用 File.WriteAllText 将一个很长的字符串写入一个文件,而另一个线程或进程正在尝试读取同一个文件。它会抛出任何异常吗?换句话说,File.WriteAllText 方法使用
这段代码的输出 string fileDateTime = "StepsGA-" + DateTime.Now.ToString("dd-MM-yyyy-HH-mm-ss") + ".txt"; st
这个问题已经有答案了: File.WriteAllText not flushing data to disk (1 个回答) 已关闭 5 年前。 我有以下代码来保存数据: File.Copy("da
我有一个问题显然是 been encountered before ,尽管解决方案对我所看到的没有帮助。 我正在尝试根据 Dictionary 的内容的 base 64 编码将数据写入文件.它应该是这
我不明白为什么会这样,但确实如此。我正在写一个这样的 csv 文件: foreach (var row in record.rows) { csv += "\n"; csv += ro
我正在构建一个必须将用户输入写入文件的简单 C# 应用程序。 我的第一个问题是我希望用户能够设置设置文件的路径,但我希望程序能够在以下启动时读取设置文件。 我的第二个问题是,如果我使用类似的东西:
我有很多文件,我想随机写入一个文件,我想做的是: StringBuilder sb = new Stringbuilder(); int x; Random rnd = new Random();
对远程路径执行 File.WriteAllText 会抛出 UnauthorizedAccessException。当我在记事本中打开文件时,我可以毫无问题地对其进行编辑。试图修改文件的进程以我自己的
我有一些代码可以将字符串保存到文件中,如下所示: string TheFileJS = HttpRuntime.AppDomainAppPath + "\\SomePath\\" + ClientFi
文档说: // Summary: // Creates a new file, writes the specified string to the file, and then closes
这个问题在这里已经有了答案: File being used by another process after using File.Create() (11 个答案) 关闭 9 年前。 当我编写如
这一定是我见过的最奇怪的异常之一。使用File.WriteAllText静态方法写入文件时,不能写入特定文件名:“PRN”。你可以用一个简单的衬垫重新创建它: File.WriteAllText("c
我有一个非常简单的 C# 程序,它迭代多个文件并替换所有文件中的字符串。 但是,当我使用 Git 比较这些文件时,它突出显示了我所有文件的更改。 我的 C# 代码是: string[] files =
我注意到我使用以下代码创建的文件中没有换行符。在我还存储文本的数据库中,这些都存在。 string story = "Critical error occurred after " + elaps
我正在使用 File.WriteAllText 创建一个文件,并使用 File.Copy 方法将同一文件复制到另一个目录。但出于某种原因,它没有在源目录中创建文件,而是将其复制到目标目录。 可能是什么
我有一些原始数据 (xml),我收到的肯定包含 unicode。我使用以下方法将它们写入文件: File.WriteAllText 这似乎删除/更改了 unicode 字符。有办法避免这种情况吗? 最
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 9 年前。 Improve
我是一名优秀的程序员,十分优秀!