By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,795 Members | 1,666 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,795 IT Pros & Developers. It's quick & easy.

Write to new Binary File has junk characters at end of file

P: n/a
I start out with a string. Which I then encode with my own algorithm
changing every characters ascii value depending on a key. I then save
it to a binary file.

When I generate the initial string, it shows up fine. When I encode
the string it shows up right. When I save the file it appends about 3
lines of random ascii characters (about the length of my original
string).

When I go back to decode the string, it works right for what it is
suppose to do, just those junk characters at the end of the file are
showing up as junk when I decode it. The application still works, it
just bothers me and looks strange.

I am using the following code to create the file:

////////
Dim ff As Integer = FreeFile()
FileOpen(ff, fileName, OpenMode.Binary, OpenAccess.ReadWrite)
FilePut(ff, encodedText)
FileClose(ff)
\\\\\\\\

Note: Before I write to the file, I msgbox the encodedText, and it
shows up right. After it's written, the file has junk at the end of
it.

How can I get the file to only produce what I want and nothing extra at
the end of it?

thanks

Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

Why dont you use the binaryreader and binarywriter class instead.

http://msdn.microsoft.com/library/de...eddatafile.asp

http://msdn.microsoft.com/library/de...ClassTopic.asp

http://msdn.microsoft.com/library/de...classtopic.asp

Ken
--------------------
"not aaron" <aa**********@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
I start out with a string. Which I then encode with my own algorithm
changing every characters ascii value depending on a key. I then save
it to a binary file.

When I generate the initial string, it shows up fine. When I encode
the string it shows up right. When I save the file it appends about 3
lines of random ascii characters (about the length of my original
string).

When I go back to decode the string, it works right for what it is
suppose to do, just those junk characters at the end of the file are
showing up as junk when I decode it. The application still works, it
just bothers me and looks strange.

I am using the following code to create the file:

////////
Dim ff As Integer = FreeFile()
FileOpen(ff, fileName, OpenMode.Binary, OpenAccess.ReadWrite)
FilePut(ff, encodedText)
FileClose(ff)
\\\\\\\\

Note: Before I write to the file, I msgbox the encodedText, and it
shows up right. After it's written, the file has junk at the end of
it.

How can I get the file to only produce what I want and nothing extra at
the end of it?

thanks
Nov 21 '05 #2

P: n/a
It seems that when I was creating the file, i was overwriting the one I
previously made. So when it overwrites the file, it adds the junk to
the end of it, and it is a new file, it won't. I won't complain, but
thanks for your quick response Ken.

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.