المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : FileStream runtime issues (Updated)



C# Programming
08-16-2009, 02:00 PM
I am having some issues using a Filestream to read a text file. The file contains repeated segments of text in the format shown below. when I attempt to read it, it will not read the entire file, it will stop at the point shown. However... if I open the text file from windows explorer and save it (not altering the text), it has no problem reading the entire file the next time the program runs.

Anyone have any ideas, or have run into this problem before?

UPDATE: After doing some more testing, I've found that FileStream IS reading to the buffer, as I can write the contents of the buffer to a new text document, and the entire file is copied. The error appears to be occuring somewhere else. I have also tried the StreamReader class and it has the same issue.


FileInfo m_fileInfo = new FileInfo("C:\\Programs\\PartyGaming\\PartyPoker\\HandHistory\\xxxxxxxxxx\\xxxxxxxxxx\\Speed #xxxxxxx_xxxxxxx.txt");
long length = m_FileInfo.Length;
byte[] buffer = new byte[length];

using (FileStream stream = new FileStream(m_FileInfo.FullName, FileMode.Open, FileAccess.Read))
{
// Read data from file to the buffer
for (long i = 0; i != length; i++)
buffer[i] = (byte)stream.ReadByte();
}


After reading to byte array I am converting to a string for further process by a StreamReader object


string data = new System.Text.UTF8Encoding(true).GetString(buffer);

MessageBox.Show(data); // Shows incomplete file


The file.....


Game #xxxxxxxxxx starts.

#Game No : xxxxxxxxxx
***** Hand History for Game xxxxxxxxxx *****
$10 USD NL Texas Hold em - Wednesday, July xx, xxxxx EDT 2009
Table Speed #xxxxxxx (Real Money)
Seat 4 is the button
Total number of players : 9
Seat 7: xxxxx ( $9.11 USD )
Seat 1: xxxxx ( $11.32 USD )
Seat 6: xxxxx ( $10 USD )
Seat 8: xxxxx ( $2 USD )
Seat 9: xxxxx ( $12.33 USD )
Seat 4: xxxxx ( $14.93 USD )
Seat 2: xxxxx ( $2.63 USD )
Seat 5: xxxxx ( $14.96 USD )
Seat 3: xxxxx ( $18.61 USD )
xxxxx posts small blind [$0.05 USD].
xxxxx posts big blind [$0.10 USD].
** Dealing down cards **
Dealt to xxxxx [ Qs 2h ]
xxxxx calls [$0.10 USD]
xxxxx calls [$0.10 USD]
xxxxx raises [$0.20 USD]
xxxxx folds
xxxxx folds
xxxxx folds
xxxxx calls [$0.15 USD]
xxxxx calls [$0.10 USD]
xxxxx calls [$0.10 USD]
xxxxx calls [$0.10 USD]
** Dealing Flop ** [ 4s, 6d, 9s ]
xxxxx checks
xxxxx checks
xxxxx bets [$0.71 USD]
xxxxx folds
xxxxx raises [$1.42 USD]
xxxxx folds
xxxxx folds
xxxxx calls [$0.71 USD]
** Dealing Turn ** [ 8h ]
xxxxx bets [$0.10 USD]
xxxxx calls [$0.10 USD]
** Dealing River ** [ 7d ]
xxxxx bets [$2.88 USD]
xxxxx folds
xxxxx does not show cards.
xxxxx wins $6.72 USD // Filestream stops reading after this line
Game #xxxxxxxxxx starts.


Any help would be appreciated