473,804 Members | 3,156 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Working with large txt files using streams

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.Re ad() method at some point it is
throwing an exception System.Componen tModel.win32Exc eption: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
6 1899
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*******@disc ussions.microso ft.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.Re ad() method at some point it is
throwing an exception System.Componen tModel.win32Exc eption: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
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*******@disc ussions.microso ft.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.Re ad() method at some point it is
throwing an exception System.Componen tModel.win32Exc eption: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
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.Unicod e or Encoding.Defaul t. 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*******@disc ussions.microso ft.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*******@disc ussions.microso ft.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.Re ad() method at some point it is
> throwing an exception System.Componen tModel.win32Exc eption: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
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*******@disc ussions.microso ft.com> wrote in message
news:53******** *************** ***********@mic rosoft.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.Re ad() method at some point it
is
throwing an exception System.Componen tModel.win32Exc eption: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
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,u nicode). i really don't known where i am going
wrong.
------------------------------------------------------
V|173848|1|4001 938833|14250316 |dsfsdfs|sdfsdf sdfsd|100017407 6|0|sdfsdfsdfsd f|6674544|23303 10451|14260601| sdfsdf||TUR|3|1 |||asdsd|1||400 1938833|16-03-1425||||asdas|s dfsdf||sdfds|Um it|Muhriz||Cice kli|TUR|asdas|1 982/11/22||1|asdasd|1| 140946|2005/06/30|asdasd|2006/06/29|1|||233|Umit Muhriz Cicekli||||||
V|173848|1|4001 938833|14250316 |dsfsdfs|sdfsdf sdfsd|100017407 6|0|sdfsdfsdfsd f|6674544|23303 10451|14260601| sdfsdf||TUR|3|1 |||asdsd|1||400 1938833|16-03-1425||||asdas|s dfsdf||sdfds|Um it|Muhriz||Cice kli|TUR|asdas|1 982/11/22||1|asdasd|1| 140946|2005/06/30|asdasd|2006/06/29|1|||233|Umit Muhriz Cicekli||||||
V|173848|1|4001 938833|14250316 |dsfsdfs|sdfsdf sdfsd|100017407 6|0|sdfsdfsdfsd f|6674544|23303 10451|14260601| sdfsdf||TUR|3|1 |||asdsd|1||400 1938833|16-03-1425||||asdas|s dfsdf||sdfds|Um it|Muhriz||Cice kli|TUR|asdas|1 982/11/22||1|asdasd|1| 140946|2005/06/30|asdasd|2006/06/29|1|||233|Umit Muhriz Cicekli||||||
V|173848|1|4001 938833|14250316 |dsfsdfs|sdfsdf sdfsd|100017407 6|0|sdfsdfsdfsd f|6674544|23303 10451|14260601| sdfsdf||TUR|3|1 |||asdsd|1||400 1938833|16-03-1425||||asdas|s dfsdf||sdfds|Um it|Muhriz||Cice kli|TUR|asdas|1 982/11/22||1|asdasd|1| 140946|2005/06/30|asdasd|2006/06/29|1|||233|Umit Muhriz Cicekli||||||
V|173848|1|4001 938833|14250316 |dsfsdfs|sdfsdf sdfsd|100017407 6|0|sdfsdfsdfsd f|6674544|23303 10451|14260601| sdfsdf||TUR|3|1 |||asdsd|1||400 1938833|16-03-1425||||asdas|s dfsdf||sdfds|Um it|Muhriz||Cice kli|TUR|asdas|1 982/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 (ObjStreamReade r.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*******@disc ussions.microso ft.com> wrote in message
news:53******** *************** ***********@mic rosoft.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.Re ad() method at some point it
is
throwing an exception System.Componen tModel.win32Exc eption: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
syed javid <sy*******@disc ussions.microso ft.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,u nicode). 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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
5689
by: Martin Dieringer | last post by:
I am trying to split a file by a fixed string. The file is too large to just read it into a string and split this. I could probably use a lexer but there maybe anything more simple? thanks m.
6
10783
by: Gaurav | last post by:
Hello, I am using visual c++ 6 and i am having problems with string to work. ******** Here is the program project.cpp********* #include <iostream.h> #include <string> #include "stdafx.h"
4
2517
by: Dag Sunde | last post by:
Just wondering if anyone have looked into this? How to split up ones JavaScript library? A lot of very specific (and small) .js files, or a few larger files. I'm thinking about load-time here... I have a gut-feeling that it will be better to use (a lot of ) smaller (very specific) files, giving you
57
25532
by: Bing Wu | last post by:
Hi all, I am running a database containing large datasets: frames: 20 thousand rows, coordinates: 170 million row. The database has been implemented with: IBM DB2 v8.1
5
1931
by: David | last post by:
Hi all: I am processing a 3D bitmaps(essentially ~1024 2D bitmaps with a size of 1MB each). If I want read large amount of radom data from this series, how could I buffer the file to get optimized performance? With WinXP pro/512MB memories and no other big programmes running at the same time. Cheers
2
27372
by: chis2k | last post by:
I need help figuring out how to get the MD5 hash of large files. I cannot go about the traditional way of reading the entire file into a byte array, because then the huge file is placed in memory, and bye bye system resources! I know there might be way using streams, but I am unsure how to implement it. Can anyone give me an example? I've tried this but it didn't work, it still loaded the entire blasted thing into memory!. public byte...
0
1285
by: Ramin Dalkouhi | last post by:
Hello, We are currently working on a serialization task which imports data into memory streams. At first, we had problems with a very high amount of data as the memory management of such memory streams is always multiplying the required memory buffer size by two. We are now "guessing" the required amount and are setting the capacity properly. The next Problem (which is the one I'am talking about) is the ToArray() method of that memory...
1
2606
by: AWHK | last post by:
Hi, I have a customer which want to upload LARGE files via a web-service and stream it into a database while it is uploading. I don't want to go out of my way and develop a large HTTP App. Module which intercepts a SOAP call and manually streams the file content to the database if it is a better solution. Any suggestions? Regards, Andreas
0
1047
by: satish | last post by:
Hi, I have an issue ..i have a text which has the information of 4 test files and they are placed in the order 4 --- this number says (total no of text files) File1 1370 -- Memory of the text file 1 File2 1988 -- Memory of text file 2 SaveToFile -- file3 644
0
10571
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10326
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10317
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10075
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7615
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.