Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi guys,
m using this code for getting bytes from file ...
VB
Dim fs As New FileStream(filepath, FileMode.Open, FileAccess.Read)
    fs.Seek(-100, SeekOrigin.End)
    Dim bytearray(100) As Byte
    Dim numbytesread As Integer = fs.Read(bytearray, 0, 100)
    textbox1.text = System.Text.Encoding.ASCII.GetString(bytearray)

-----------------------
the prome what m facing is while reading to any text file it works fine but when i read an exe file it read 100 bytes but not from last but actualy it is reading above of few last lines , so by this m not getting last few lines ... i dont now wht was the prome ....

help needed ..
thnxxs in advance ...
Posted
Updated 31-May-15 3:01am
v2

1 solution

Yes, it is...it's just that what is in the EXE file is not that printable.

EXE files are binary, not text - so they contain a lot of values which are outside the ASCII "printable" set: some of these are "mapped to control codes (which control how data is displayed on some devices), and a larger number of "invalid" values as far as strict ASCII is concerned.
It's not the read that is causing the problem, it's the display! Use the debugger and examine the content of bytearray and you will see all of the values.

But...trying to display the "end" of binary files as any form of text is probably a fairly silly one - what are you actually trying to achieve with this?
 
Share this answer
 
Comments
Member 10521418 31-May-15 10:42am    
m not using Ascii to display bytes but what m using is
system.text.encoding.default.getstring(bytearray) and m trying to get last 100 bytes without single byte to loss.
Member 10521418 31-May-15 10:57am    
and if display is the prome then why the byte from the starting is showing but not the lastone ..
OriginalGriff 31-May-15 11:25am    
Because binary data can contain any value - and it isn't necessarily data that can be displayed.
If you display the values as their Hex representations - try BitConverter.ToString(bytearray) - you will see the actual values.
But you can't expect any binary data to be readable - even if you try to display it as Unicode it probably won't work.

As I said, what are you trying to achieve by doing this?
Member 10521418 31-May-15 12:36pm    
i used as u said bitconverter.tostring & yippppiiii my prome
has solved ... it is showing all bytes as i wished .... thnxxxs
thnxxxs originalGriff thnxxx you very much ...
i want the actual values and that small change solved all my prome ... thnxxs you ....
OriginalGriff 31-May-15 12:53pm    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900