C# 文件发送、流问题
我有一个服务器和一个客户端。服务器向客户端发送可执行文件和 input.txt。客户端应该执行它并将输出发送到服务器,但我有一个问题。当我尝试运行可执行文件时,它给出了有关参数格式的错误。之后,我将输入文件保存为(仅进行快速字符添加和删除)可执行文件,将其保存为不同的文件后成功运行,尽管它具有确切的内容。
我正在使用 BinaryWriter 保存文件:
FileStream fs = File.Open(filename, FileMode.OpenOrCreate);
BinaryWriter BW = new BinaryWriter(fs);
.......
fs.Close();
BW.Close();
在关闭 BinaryWriter 和文件流后,我使用参数 input.txt 运行可执行文件。我认为保存文件或关闭流时存在问题,但我还找不到它。任何帮助将不胜感激...
I have a server and a client. Server sends an executable and an input.txt to the client. Client should execute it and send output to the server but I have a problem. When I try to run executable it gives an error about argument format. After that I save input file as (make just a quick char addition and removing) executable runs succesfully after saving it as a different file altough it has the exact content.
I'm saving the file using BinaryWriter :
FileStream fs = File.Open(filename, FileMode.OpenOrCreate);
BinaryWriter BW = new BinaryWriter(fs);
.......
fs.Close();
BW.Close();
I run executable with the parameter input.txt after closing the BinaryWriter and filestream.I think there is a problem with saving the file or maybe closing the stream but I couldnot find it yet. Any help would be appreciated...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个可能的问题是最后两行的顺序错误:
您至少应该颠倒它们,但最好使用
using
块:A possible problem is that the last 2 lines are in the wrong order:
You should at least reverse them, but even better use
using
blocks: