Click here to Skip to main content
15,897,093 members
Home / Discussions / C#
   

C#

 
GeneralRe: Need Help in multithread C# socket programming!!! Pin
yum 20109-Jul-10 2:29
yum 20109-Jul-10 2:29 
GeneralRe: Need Help in multithread C# socket programming!!! Pin
Eddy Vluggen9-Jul-10 3:30
professionalEddy Vluggen9-Jul-10 3:30 
GeneralRe: Need Help in multithread C# socket programming!!! Pin
yum 20109-Jul-10 10:44
yum 20109-Jul-10 10:44 
GeneralRe: Need Help in multithread C# socket programming!!! Pin
Eddy Vluggen9-Jul-10 12:01
professionalEddy Vluggen9-Jul-10 12:01 
GeneralRe: Need Help in multithread C# socket programming!!! Pin
yum 201010-Jul-10 5:35
yum 201010-Jul-10 5:35 
QuestionObtain Solution Classes types in Design Time Pin
adiel20087-Jul-10 5:34
adiel20087-Jul-10 5:34 
AnswerRe: Obtain Solution Classes types in Design Time Pin
Abhinav S7-Jul-10 7:04
Abhinav S7-Jul-10 7:04 
QuestionHow to read a binary file byte by byte and compare its utf8 rendition? [modified] Pin
Shaareable7-Jul-10 5:06
Shaareable7-Jul-10 5:06 
Greetings,

I have a file which is binary. It contains lots of text encoded in UTF8 and binary blobs. I am trying to find a specific section which is 'xref' located somewhere at the end of the file.

So I need to open the file, read the file from the beginning, and find something.
What I have, below, is probably horribly inefficient and perhaps even plain wrong.

Hence I write this in the hope of getting advice from my more experienced peers...
First off, I am maintaining a lock on the file with the filereader, right? Isn't that bad?


Please tell how you would do this Smile | :)

thanks,

<pre>
string path,data;

Boolean munching = true;
long length;
int offset = 0;
int count = 4;
UTF8Encoding utf8 = new UTF8Encoding();


if (txtFilePath.Text != "")
{
path = txtFilePath.Text;

if (File.Exists(path))
{
FileStream fs = File.OpenRead(path);
length = fs.Length;
byte[] buffer = new byte[count];
offset = Convert.ToInt32(length) - count;
int lastBytes = Convert.ToInt32(length-count);

fs.Seek(offset, 0);

while (munching)
{

fs.Read(buffer, 0, count);
data = utf8.GetString(buffer);
if (data == "xref")
{
// Yay! I've finally figured this part out.
}

offset = offset - 1;
fs.Seek(offset, 0);


</pre>



-- Modified Wednesday, July 7, 2010 12:27 PM
AnswerRe: How to read a binary file byte by byte and compare its utf8 rendition? Pin
harold aptroot7-Jul-10 5:11
harold aptroot7-Jul-10 5:11 
AnswerRe: How to read a binary file byte by byte and compare its utf8 rendition? Pin
OriginalGriff7-Jul-10 5:19
mveOriginalGriff7-Jul-10 5:19 
AnswerRe: How to read a binary file byte by byte and compare its utf8 rendition? Pin
OriginalGriff7-Jul-10 5:28
mveOriginalGriff7-Jul-10 5:28 
AnswerRe: How to read a binary file byte by byte and compare its utf8 rendition? Pin
Richard MacCutchan7-Jul-10 7:03
mveRichard MacCutchan7-Jul-10 7:03 
GeneralRe: How to read a binary file byte by byte and compare its utf8 rendition? Pin
Shaareable7-Jul-10 7:15
Shaareable7-Jul-10 7:15 
QuestionHow does one programatically arrange Outlook Tasks by category? Pin
euroazn7-Jul-10 4:24
euroazn7-Jul-10 4:24 
QuestionSeagull Bartender Application Pin
Hum Dum7-Jul-10 0:15
Hum Dum7-Jul-10 0:15 
AnswerRe: Seagull Bartender Application Pin
Pete O'Hanlon7-Jul-10 0:23
mvePete O'Hanlon7-Jul-10 0:23 
GeneralRe: Seagull Bartender Application Pin
Hum Dum7-Jul-10 0:55
Hum Dum7-Jul-10 0:55 
GeneralRe: Seagull Bartender Application Pin
Pete O'Hanlon7-Jul-10 1:37
mvePete O'Hanlon7-Jul-10 1:37 
AnswerRe: Seagull Bartender Application Pin
Abhinav S7-Jul-10 1:24
Abhinav S7-Jul-10 1:24 
GeneralRe: Seagull Bartender Application Pin
Hum Dum7-Jul-10 1:33
Hum Dum7-Jul-10 1:33 
GeneralRe: Seagull Bartender Application Pin
Abhinav S7-Jul-10 1:50
Abhinav S7-Jul-10 1:50 
AnswerRe: Seagull Bartender Application Pin
R. Giskard Reventlov7-Jul-10 2:15
R. Giskard Reventlov7-Jul-10 2:15 
QuestionSendMessage to control with non-fixed ControlID Pin
LordZoster7-Jul-10 0:08
LordZoster7-Jul-10 0:08 
AnswerRe: SendMessage with variable ControlID Pin
freakyit7-Jul-10 1:11
freakyit7-Jul-10 1:11 
GeneralRe: SendMessage with variable ControlID Pin
LordZoster7-Jul-10 1:23
LordZoster7-Jul-10 1:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.