|
-
February 24th, 2008, 04:04 PM
#1
accessing a specific area in a file...?
How can i access a specific range of characters in file?
for example I want to open a text file and read from character #39 to character #99.
Is there a way of doing this without reading the whole file using the FileStream.ReadToEnd() Method, and then accessing the specific characters???
The ReadToEnd method could take a long time if it's a big file, and i only need a small portion of the file content...
Rate this post if you found it useful!
10X, gilly914
-
February 25th, 2008, 08:38 AM
#2
Re: accessing a specific area in a file...?
-
February 25th, 2008, 01:43 PM
#3
Re: accessing a specific area in a file...?
Or:
Code:
//Create a file stream from an existing file.
FileInfo fi=new FileInfo("c:\\csc.txt");
FileStream fs=fi.OpenRead();
//Read 100 bytes into an array from the specified file.
int nBytes=100;
byte[] ByteArray=new byte[nBytes];
int nBytesRead=fs.Read(ByteArray, 0, nBytes);
Console.WriteLine("{0} bytes have been read from the specified file.", nBytesRead.ToString());
Cheers,
Jon
-
February 25th, 2008, 01:47 PM
#4
Re: accessing a specific area in a file...?
Thanks!
I'll try it, and get back to you...
Rate this post if you found it useful!
10X, gilly914
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
|