How to read Textfile FAST into memory and then read LINE
-
Hi, have to parse a big Textfile with about 33000 lines and at the moment this is very slow. A colleague advised me to read the file into a buffer (byte Array) and than parse it. Thats ok, but i need the "readline" functionality. How can i read the buffer line-by-line like the Streamreader? I'm sure someone knows :-D
-
Hi, have to parse a big Textfile with about 33000 lines and at the moment this is very slow. A colleague advised me to read the file into a buffer (byte Array) and than parse it. Thats ok, but i need the "readline" functionality. How can i read the buffer line-by-line like the Streamreader? I'm sure someone knows :-D
I guess you could always convert the byte array into a string and then split it based on Environment.NewLine. This sounds as though it wouldn't be very performant either.
Deja View - the feeling that you've seen this post before.
-
Hi, have to parse a big Textfile with about 33000 lines and at the moment this is very slow. A colleague advised me to read the file into a buffer (byte Array) and than parse it. Thats ok, but i need the "readline" functionality. How can i read the buffer line-by-line like the Streamreader? I'm sure someone knows :-D
you could use FileStream to copy the file into a MemoryStream, and later use StreamReader from MemoryStream to parse it.
FileStream fs = new FileStream("text.txt", FileMode.Open, FileAccess.Read); MemoryStream ms = new MemoryStream(); byte[] buf = new byte[4096]; int bytes = 0; while((bytes = fs.Read(buf, 0, 4096)) > 0) { ms.Write(buf, 0, bytes); } fs.close(); StreamReader sr = new StreamReader(ms); string x = sr.ReadLine();
My second computer is your linux box.