Reputation: 563
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...
Upvotes: 0
Views: 535
Reputation: 273264
A possible problem is that the last 2 lines are in the wrong order:
fs.Close();
BW.Close(); // tries to close the file and maybe flush some buffers
You should at least reverse them, but even better use using
blocks:
using (FileStream fs = File.Open(filename, FileMode.OpenOrCreate))
using (BinaryWriter BW = new BinaryWriter(fs))
{
.......
}
Upvotes: 3