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

Working with large txt files using streams

P: n/a
hi all,

I am getting an error when i process 1 MB txt file using StreamReader and i
am reading char by char using streamReader.Read() method at some point it is
throwing an exception System.ComponentModel.win32Exception:The handle is
invalid.
Any help for this problem or any kind of informaiton to process large files
the file size can be 10 MB.

thanks in advance
Syed

Nov 17 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hi Syed,

Just a thought, is the text file UTF8 encoded? If not, specify another encoding when creating the StreamReader.
On Sat, 16 Jul 2005 10:05:02 +0200, syed javid"" <sy*******@discussions.microsoft.com> wrote:
hi all,

I am getting an error when i process 1 MB txt file using StreamReader and i
am reading char by char using streamReader.Read() method at some point it is
throwing an exception System.ComponentModel.win32Exception:The handle is
invalid.
Any help for this problem or any kind of informaiton to process large files
the file size can be 10 MB.

thanks in advance
Syed



--
Happy coding!
Morten Wennevik [C# MVP]
Nov 17 '05 #2

P: n/a
Hi Morten,

The text file is having arabic data, but i tested the streamReader with
UTF8 encoding and still the same error occurs.

Thanks
"Morten Wennevik" wrote:
Hi Syed,

Just a thought, is the text file UTF8 encoded? If not, specify another encoding when creating the StreamReader.
On Sat, 16 Jul 2005 10:05:02 +0200, syed javid"" <sy*******@discussions.microsoft.com> wrote:
hi all,

I am getting an error when i process 1 MB txt file using StreamReader and i
am reading char by char using streamReader.Read() method at some point it is
throwing an exception System.ComponentModel.win32Exception:The handle is
invalid.
Any help for this problem or any kind of informaiton to process large files
the file size can be 10 MB.

thanks in advance
Syed



--
Happy coding!
Morten Wennevik [C# MVP]

Nov 17 '05 #3

P: n/a
Hi Syed,

If you don't specify an encoding when creating the StreamReader, it will try to decode the file as UTF8. Try specifying Encoding.Unicode or Encoding.Default. If both fail I'm afraid I'm out of ideas and you might want to start a new thread with your question.
On Sun, 17 Jul 2005 07:56:01 +0200, syed javid"" <sy*******@discussions.microsoft.com> wrote:
Hi Morten,

The text file is having arabic data, but i tested the streamReader with
UTF8 encoding and still the same error occurs.

Thanks
"Morten Wennevik" wrote:
Hi Syed,

Just a thought, is the text file UTF8 encoded? If not, specify another encoding when creating the StreamReader.
On Sat, 16 Jul 2005 10:05:02 +0200, syed javid"" <sy*******@discussions.microsoft.com> wrote:
> hi all,
>
> I am getting an error when i process 1 MB txt file using StreamReader and i
> am reading char by char using streamReader.Read() method at some point it is
> throwing an exception System.ComponentModel.win32Exception:The handle is
> invalid.
> Any help for this problem or any kind of informaiton to process large files
> the file size can be 10 MB.
>
> thanks in advance
> Syed
>
>
>
>
>
>


--
Happy coding!
Morten Wennevik [C# MVP]


--
Happy coding!
Morten Wennevik [C# MVP]
Nov 17 '05 #4

P: n/a
hmm. 1MB is not large, so don't think that is the issue. Could you post a
small but complete code sample that shows the error?

--
William Stacey [MVP]

"syed javid" <sy*******@discussions.microsoft.com> wrote in message
news:53**********************************@microsof t.com...
hi all,

I am getting an error when i process 1 MB txt file using StreamReader and
i
am reading char by char using streamReader.Read() method at some point it
is
throwing an exception System.ComponentModel.win32Exception:The handle is
invalid.
Any help for this problem or any kind of informaiton to process large
files
the file size can be 10 MB.

thanks in advance
Syed


Nov 17 '05 #5

P: n/a
Hi William ,
i am sending u the text file data and code to process the text data.
Note : All this processing is done in windows service and checked with all
the encodings (Default,UTF8,unicode). i really don't known where i am going
wrong.
------------------------------------------------------
V|173848|1|4001938833|14250316|dsfsdfs|sdfsdfsdfsd |1000174076|0|sdfsdfsdfsdf|6674544|2330310451|1426 0601|sdfsdf||TUR|3|1|||asdsd|1||4001938833|16-03-1425||||asdas|sdfsdf||sdfds|Umit|Muhriz||Cicekli|T UR|asdas|1982/11/22||1|asdasd|1|140946|2005/06/30|asdasd|2006/06/29|1|||233|Umit Muhriz Cicekli||||||
V|173848|1|4001938833|14250316|dsfsdfs|sdfsdfsdfsd |1000174076|0|sdfsdfsdfsdf|6674544|2330310451|1426 0601|sdfsdf||TUR|3|1|||asdsd|1||4001938833|16-03-1425||||asdas|sdfsdf||sdfds|Umit|Muhriz||Cicekli|T UR|asdas|1982/11/22||1|asdasd|1|140946|2005/06/30|asdasd|2006/06/29|1|||233|Umit Muhriz Cicekli||||||
V|173848|1|4001938833|14250316|dsfsdfs|sdfsdfsdfsd |1000174076|0|sdfsdfsdfsdf|6674544|2330310451|1426 0601|sdfsdf||TUR|3|1|||asdsd|1||4001938833|16-03-1425||||asdas|sdfsdf||sdfds|Umit|Muhriz||Cicekli|T UR|asdas|1982/11/22||1|asdasd|1|140946|2005/06/30|asdasd|2006/06/29|1|||233|Umit Muhriz Cicekli||||||
V|173848|1|4001938833|14250316|dsfsdfs|sdfsdfsdfsd |1000174076|0|sdfsdfsdfsdf|6674544|2330310451|1426 0601|sdfsdf||TUR|3|1|||asdsd|1||4001938833|16-03-1425||||asdas|sdfsdf||sdfds|Umit|Muhriz||Cicekli|T UR|asdas|1982/11/22||1|asdasd|1|140946|2005/06/30|asdasd|2006/06/29|1|||233|Umit Muhriz Cicekli||||||
V|173848|1|4001938833|14250316|dsfsdfs|sdfsdfsdfsd |1000174076|0|sdfsdfsdfsdf|6674544|2330310451|1426 0601|sdfsdf||TUR|3|1|||asdsd|1||4001938833|16-03-1425||||asdas|sdfsdf||sdfds|Umit|Muhriz||Cicekli|T UR|asdas|1982/11/22||1|asdasd|1|140946|2005/06/30|asdasd|2006/06/29|1|||233|Umit Muhriz Cicekli|||||||

-------------------------------------------------------
// Reading the text file using stream reader
//Open the file using stream reader

ObjStreamReader = new StreamReader(e.FullPath,System.Text.Encoding.UTF8) ;

char c = ' ';
while (ObjStreamReader.Peek() > 0)
{
// Reading the line char by char
c = (char) ObjStreamReader.Read();
if (c != '\n')
{
strLine += c;
}
else
{
// building the Xml by splitting the strLine and
sending to the queue.
}
//Going to next line
} // end of while loop

thanks
syed

"William Stacey [MVP]" wrote:
hmm. 1MB is not large, so don't think that is the issue. Could you post a
small but complete code sample that shows the error?

--
William Stacey [MVP]

"syed javid" <sy*******@discussions.microsoft.com> wrote in message
news:53**********************************@microsof t.com...
hi all,

I am getting an error when i process 1 MB txt file using StreamReader and
i
am reading char by char using streamReader.Read() method at some point it
is
throwing an exception System.ComponentModel.win32Exception:The handle is
invalid.
Any help for this problem or any kind of informaiton to process large
files
the file size can be 10 MB.

thanks in advance
Syed



Nov 17 '05 #6

P: n/a
syed javid <sy*******@discussions.microsoft.com> wrote:
i am sending u the text file data and code to process the text data.
Note : All this processing is done in windows service and checked with all
the encodings (Default,UTF8,unicode). i really don't known where i am going
wrong.


Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.