|
-
Oct 29th, 2002, 03:17 PM
#1
Thread Starter
Registered User
Reading large files fast
Hello everyone,
I'm trying to get the the Hashcode of a file to look whether it corrupted or not. The problem is, that the file reading method that i use is atrociously slow (especially with files over 50mb) 
Code:
StreamReader DataFile = new StreamReader(
(System.IO.Stream)File.OpenRead("somefile.any"),System.Text.Encoding.ASCII);
string Checksum = DataFile.ReadToEnd().GetHashCode().ToString();
could anyone here please suggest me something that would be faster? Would a loop maybe faster? I know it can be faster, but how?
Tank you very much in advance!
-
Oct 29th, 2002, 04:11 PM
#2
PowerPoster
Check out the bufferstream() class. This class is optimized to provide the most efficient file access.
-
Oct 29th, 2002, 05:08 PM
#3
Thread Starter
Registered User
Ok, I got that, but somehow the checksum does only change if i change the file length :/.
Could you please show me an example of how to read the whole file into a buffer and get the HashCode? Thanx!
-
Oct 29th, 2002, 06:21 PM
#4
PowerPoster
How about this?
Code:
using System;
using System.IO;
public class FileAccessExample
{
public static void Main()
{
string path = @"c:\test.txt";
BufferedStream buff = new BufferedStream (File.Open(path, FileMode.Open));
Console.WriteLine(buff.GetHashCode());
}
}
-
Oct 29th, 2002, 07:22 PM
#5
Lively Member
Code:
StreamReader sRetr = File.OpenText(PATH);
while (sRetr.Peek() > -1)
{
sData = sData + sRetr.ReadLine();
}
Try reading it line by line as above. I don't know if this will help but I suppose its worth a try!
-toto
-
Oct 29th, 2002, 07:51 PM
#6
Thread Starter
Registered User
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|