Computer Science Canada

File Streams

Author:  Justin_ [ Sat Mar 11, 2006 5:30 pm ]
Post subject:  File Streams

Okay I'm not sure if my question is .NET specific or not, but when I create an output filestream and output strings the begning of each new stream a char that looks like a rectangle appears. I don't know what its called but it looks like a rectangle that is not filled in.

Basically I'd like to not have that rectangle lol. Any suggestions? (supposing you know what I'm talking about)

Author:  md [ Sat Mar 11, 2006 6:06 pm ]
Post subject: 

The rectangle would be a character that has no graphical representation. Since you have neglected to post any code it's rather difficult to be able to say why it's getting written.

Really, you've been here long enough to know to post code. Failing to do so is rather poor on your part.

Author:  Justin_ [ Sat Mar 11, 2006 6:23 pm ]
Post subject: 

There's nothing exciting about the code. It's exactly as I described, take a look:
c++:

static int Main()
    {
        string nameOfFile = Console.ReadLine();
       

        FileStream fstMembers = new FileStream(nameOfFile, FileMode.Create);
        BinaryWriter wrtMembers = new BinaryWriter(fstMembers);
       

        try
        {
            wrtMembers.Write("James Bloch");
            wrtMembers.Write("Catherina Wallace");
            wrtMembers.Write("Bruce Lamont");
            wrtMembers.Write("Douglas Truth");
        }
        finally
        {
            wrtMembers.Close();
            fstMembers.Close();
        }
        nameOfFile = Console.ReadLine();
        return 0;
    }


I'm guessing its got to do with the way Write handles string streams. Maybe there is a better class to deal with file streams.

Author:  wtd [ Sat Mar 11, 2006 7:01 pm ]
Post subject: 

Is this C++ or C#?

Author:  Justin_ [ Sat Mar 11, 2006 9:57 pm ]
Post subject: 

c#

Author:  Justin_ [ Sat Mar 11, 2006 10:47 pm ]
Post subject: 

I switched to a different class and it works out. Thanks Cornflake for specifying what that crazy rectangle was. Do you know if it has a name?

Author:  rizzix [ Sat Mar 11, 2006 11:00 pm ]
Post subject: 

wtd wrote:
Is this C++ or C#?


c'mon.. the "finally" keyword should have been a big hint Wink

Author:  wtd [ Sat Mar 11, 2006 11:32 pm ]
Post subject: 

Are you writing text as binary to a file, then expecting it to look fine in a text editor?

Author:  Justin_ [ Sat Mar 11, 2006 11:40 pm ]
Post subject: 

Correct me if I'm wrong, but isn't all text stored as binary inside a file?

Author:  wtd [ Sat Mar 11, 2006 11:47 pm ]
Post subject: 

Ultimately everything is binary, but if you have an ASCII text file, and write to it as such, the correct line endings will be used. If you have a C# program and run it on Windows, it'll write a carriage return linefeed combo, and on on a *nix it'll write the proper newline for that platform.


: