Inputing from Large Text Files

bpayne111

Well-known member
Joined
Feb 28, 2003
Messages
326
Location
BFE
I am aware that a StreamReader wont work for reading text files with large amounts of data. So what do i use instead? I need to input from various sized files into a database, sometimes the files may be very large. I CAN assume that the files will be no larger than a file in notepad though, for the data im reading always comes from notepad.
thanks
brandon
 
Instead of using ReadToEnd, you can just use the Read method in a loop to read the file chunk by chunk. There should be no limit imposed on you there.
 
that sounds perfect... so itll work as long as i do it line by line? (i could have sworn i had trouble with this before on another project
 
If you want to read line by line, you use ReadLine. Read reads in chunks, not lines, meaning it will read a certain number of characters over and over until it reaches the end. There is an example or two in the MSDN.
 
I know how to use them... but i thought they had limits as too how large of files they could use. Can a notepad file be bigger than a SreamReaders buffer?
 
A NotePad file? You mean a TextFile? TextFiles are just files containing text with no special formatting. They can be any size.

StreamReaders buffer only really matter when reading a whole file, since it needs to buffer the whole file first. When reading in chunks, it doesnt matter.
 
Back
Top