Not able to Read Contents for File while Reading Huge Amount of data.
-
Hi All, I am not able to Contents of File when it exceeds length of 1024. CFile file; if(file.open("C:\\users\\rakesh\\Desktop\\myText.xml",CFile::modeRead)) { return false; } TCHAR buffer[100000];//say content is very Big file.read(buffer,100000); file.close(); I am not able to get the Contents into Buffer. But i am able to get the Length of the File with int len = file.GetLength(). I am getting Junk into Buffer. What may be the reason i am not able to get it into buffer. Uday.
-
Hi All, I am not able to Contents of File when it exceeds length of 1024. CFile file; if(file.open("C:\\users\\rakesh\\Desktop\\myText.xml",CFile::modeRead)) { return false; } TCHAR buffer[100000];//say content is very Big file.read(buffer,100000); file.close(); I am not able to get the Contents into Buffer. But i am able to get the Length of the File with int len = file.GetLength(). I am getting Junk into Buffer. What may be the reason i am not able to get it into buffer. Uday.
janaswamy uday wrote:
file.read(buffer,100000);
You should always check the return value of an API function call. See, for instance, the code sample in the _read documentation page[^]. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hi All, I am not able to Contents of File when it exceeds length of 1024. CFile file; if(file.open("C:\\users\\rakesh\\Desktop\\myText.xml",CFile::modeRead)) { return false; } TCHAR buffer[100000];//say content is very Big file.read(buffer,100000); file.close(); I am not able to get the Contents into Buffer. But i am able to get the Length of the File with int len = file.GetLength(). I am getting Junk into Buffer. What may be the reason i am not able to get it into buffer. Uday.
Try Using
CStdioFile
. Regards, Paresh.
-
Hi All, I am not able to Contents of File when it exceeds length of 1024. CFile file; if(file.open("C:\\users\\rakesh\\Desktop\\myText.xml",CFile::modeRead)) { return false; } TCHAR buffer[100000];//say content is very Big file.read(buffer,100000); file.close(); I am not able to get the Contents into Buffer. But i am able to get the Length of the File with int len = file.GetLength(). I am getting Junk into Buffer. What may be the reason i am not able to get it into buffer. Uday.
janaswamy uday wrote:
if(file.open("C:\\users\\rakesh\\Desktop\\myText.xml",CFile::modeRead))
What you have posted will not even compile. That aside, this should be:
if (! file.Open("C:\\users\\rakesh\\Desktop\\myText.xml", CFile::modeRead))
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
Hi All, I am not able to Contents of File when it exceeds length of 1024. CFile file; if(file.open("C:\\users\\rakesh\\Desktop\\myText.xml",CFile::modeRead)) { return false; } TCHAR buffer[100000];//say content is very Big file.read(buffer,100000); file.close(); I am not able to get the Contents into Buffer. But i am able to get the Length of the File with int len = file.GetLength(). I am getting Junk into Buffer. What may be the reason i am not able to get it into buffer. Uday.
janaswamy uday wrote:
if(file.open("C:\\users\\rakesh\\Desktop\\myText.xml",CFile::modeRead))
{
return false;
}This means if you successfully open the file you return
false
instead of reading the file into your buffer.I must get a clever new signature for 2011.
-
Hi All, I am not able to Contents of File when it exceeds length of 1024. CFile file; if(file.open("C:\\users\\rakesh\\Desktop\\myText.xml",CFile::modeRead)) { return false; } TCHAR buffer[100000];//say content is very Big file.read(buffer,100000); file.close(); I am not able to get the Contents into Buffer. But i am able to get the Length of the File with int len = file.GetLength(). I am getting Junk into Buffer. What may be the reason i am not able to get it into buffer. Uday.
It may or may not be causing this issue, but the stack has limited space, and allocating 100,000 TCHARs on the stack is not a good idea. you should instead use
LPTSTR buffer = new TCHAR[100000];
file.read();
//process data
delete []buffer; -
It may or may not be causing this issue, but the stack has limited space, and allocating 100,000 TCHARs on the stack is not a good idea. you should instead use
LPTSTR buffer = new TCHAR[100000];
file.read();
//process data
delete []buffer;Thank you very much Bruck. I will try with that.