
-----------------------------------
Justin_
Sat Mar 11, 2006 5:30 pm

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)

-----------------------------------
md
Sat Mar 11, 2006 6:06 pm


-----------------------------------
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.

-----------------------------------
Justin_
Sat Mar 11, 2006 6:23 pm


-----------------------------------
There's nothing exciting about the code.  It's exactly as I described, take a look: 

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.

-----------------------------------
wtd
Sat Mar 11, 2006 7:01 pm


-----------------------------------
Is this C++ or C#?

-----------------------------------
Justin_
Sat Mar 11, 2006 9:57 pm


-----------------------------------
c#

-----------------------------------
Justin_
Sat Mar 11, 2006 10:47 pm


-----------------------------------
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?

-----------------------------------
rizzix
Sat Mar 11, 2006 11:00 pm


-----------------------------------
Is this C++ or C#?

c'mon.. the "finally" keyword should have been a big hint ;)

-----------------------------------
wtd
Sat Mar 11, 2006 11:32 pm


-----------------------------------
Are you writing text as binary to a file, then expecting it to look fine in a text editor?

-----------------------------------
Justin_
Sat Mar 11, 2006 11:40 pm


-----------------------------------
Correct me if I'm wrong, but isn't all text stored as binary inside a file?

-----------------------------------
wtd
Sat Mar 11, 2006 11:47 pm


-----------------------------------
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.
