问题标签 [streamwriter]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
5 回答
43726 浏览

.net - 将 .NET StreamWriter 输出重定向到字符串变量

我想知道是否可以将 StreamWriter 输出重定向到变量

就像是

那么 myString 将包含 Foo。我想这样做的原因是重用一个复杂的函数。我可能应该将它重构为一个字符串返回函数,但它仍然是一个很好的 hack 知道

0 投票
2 回答
1040 浏览

.net - 从 .NET 启动进程但 RedirectedStandardOutput 不支持 UTF-8

我正在尝试使用以下代码从 .NET 调用 php 的 HTML 净化器:

..一切正常,除了...我无法取回非asci字符。例如,在输入中提供一些韩语字符会返回问号作为输出。

即使 HTMLPurifier 函数被绕过并且我只是想简单地提供输入 .NET,将其存储在 php 变量中,然后将该变量回显到输出,也会发生这种情况。

有任何想法吗?

0 投票
4 回答
3076 浏览

asp.net - Having problem opening/writing to a text file in ASP.NET

I want to write some stats to a text file every time a person loads a page. But every once in awhile I am getting at 'Could Not Open File, Already in use' type of error. I can not 100% replicate this error it is very erratic. My code is

My question is, how can I lock and unlock the file so I stop getting the erratic errors?

Thanks

0 投票
4 回答
3926 浏览

c# - 为什么 StreamWriter 在 Windows 服务中不起作用?

我有这个简单的代码,记录将日志附加到文本文件:

这在 Windows 窗体应用程序中完美运行。然而,使用instsrv 和 srvany技巧,我把它变成了一个 Windows 服务。该服务运行良好,访问数据库,执行查询和所有...除了这个 StreamWriter。日志只是没有得到应有的更新。任何想法为什么?

0 投票
4 回答
1869 浏览

.net - 为什么 .NET Framework StreamReader / Writer 默认为 UTF8 编码?

我只是在查看 StreamReader / Writer 的构造函数,我注意到它默认使用 UTF8。有谁知道这是为什么?我原以为默认使用 Unicode 会更安全。

0 投票
4 回答
2953 浏览

c# - Streamwriter 写入但给出网络异常

我正在尝试通过 Web 服务插入数据。下面的代码写入数据库;但是,我有一个错误(见底部)。这里出了什么问题?以及如何解决?

错误:

System.Net.WebException 未处理 Message="请求已中止:请求已取消。" Source="System" StackTrace: 在 System.Net.ConnectStream.System.Net.ICloseEx.CloseEx(CloseExState closeState) 在 System.Net.ConnectStream.Dispose(Boolean) 的 System.Net.ConnectStream.CloseInternal(Boolean internalCall, Boolean aborting)在 System.IO.Stream.Close() 在 System.IO.StreamWriter.Dispose(Boolean disposing) 在 System.IO.StreamWriter.Close() 在 ConsoleApplication1.Program.Main(String[] args) 在 C:/ Program Files/Program.cs:第 62 行 System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) 在 Microsoft.VisualStudio.HostingProcess。

0 投票
2 回答
28205 浏览

c# - 我需要做 StreamWriter.flush() 吗?

假设这个 C# 代码:

我的问题是:

  1. 我是否需要在循环内使用刷新来保持顺序?
  2. 回国MemoryStream.ToArray()合法吗?我使用using-block 作为约定,我担心它会搞砸。
0 投票
6 回答
10890 浏览

c# - StreamWriter - 不附加到创建的文件

我正在使用 StreamWriter 对象写入由构造函数创建或已存在的文件。如果文件存在,那么它会附加数据。如果没有,那么它应该创建一个文件,然后还附加数据。问题是当需要创建文件时,StreamWriter 构造函数会创建文件但不会向文件写入任何数据。

编辑:感谢您的回答。using 块负责关闭编写器。至于其他人说它对他们有用,我可以给你任何信息来进一步诊断问题吗?该文件通过网络本地化。这可能是一个潜在的问题。我间歇性地收到错误消息,“找不到路径的一部分......”和“指定的网络名称不再可用”。

0 投票
4 回答
149919 浏览

c# - 将文件写入 Web 服务器 - ASP.NET

我只是想将 TextBox 控件的内容写入 Web 服务器目录根目录中的文件...如何指定它?

请记住,我正在本地测试它......它一直将文件写入我的程序 files\visual studio\Common\IDE 目录而不是我的项目目录(我假设 root 是 Web 服务器启动时的位置) .

我的问题是否与在我的 web.config 中指定正确的位置有关?我试过了,还是不行。。。

非常感谢...

0 投票
4 回答
7886 浏览

.net - How I get the best performance out of .NET's StreamWriter in C#?

What is the recommended approach to get the best performance when we need to create text files bigger than 10 MB?

There are multiple sections in the code that need to write stuff to a single file. This means a lot of text lines.

Option #1 (This logic will be called at several times):

  1. Create a StreamWriter instance
  2. Write some lines (according to some business logic)
  3. Close the StreamWriter instance

Option #2:

  1. Create a StreamWriter at the begining of the program
  2. Write all of the lines from diferent sections of the code.
  3. Close the StreamWriter at the very end when nothing else need to be written.

Option #3: Any other?

Remember the output file could be bigger than 10 MB.