Indexing-Reading Big plain text files
Indexing-Reading Big plain text files
- Subject: Indexing-Reading Big plain text files
- From: Busman <email@hidden>
- Date: Wed, 16 Jan 2002 13:43:04 -0300
Hi...
I'm using NSFileHanle to read a big File of plain text, (need to
index it, find some special character and get the location to save as
index, in a array maybe, to re use it later), how I can work that way
with the NSFileHandle-NSData? or maybe some other class?, with
NSFileHandle can get the current filepointer and then make use a seek
method, but for reading a NSFileHandle data just can use NSData
objet, then how to read the NSData object and get the exact file
location of the character?, making small counts and reading byte for
byte?, maybe some class can save some job, a way of read text direct
from a file and have access to he current file location?.... The job
is done and work in java (slow), .. my english is not very good =) ,
soo maybe the code explain me better...
public void makeIndex(int totalApp)throws IOException{
//reading the file this way is very expensive...
RandomAccessFile tabla=new RandomAccessFile("thepath","r");
//totalApp give the number of special character that are in the file
//other method make that job (yeah can save time using vector
//but just want to explain the idea to make it ObjC :)
//index is the arrayindex locate before...
index=new long[totalApp];
String aux = "";
int i=0;
//read the entire file to the end... an read for lines
//(this way is the problem, very slowww)
//when fin the character, save the pointer and then the counter
// is +1 when is all done file is close...
while(tabla.getFilePointer()<tabla.length())
{
aux = tabla.readLine();
if(aux.equals("@"))
index[i++]=tabla.getFilePointer();
}
tabla.close();
}
--
-----------------------
Busman
http://thelastline.dhs.org
email@hidden
"We are TheLastLine"
-----------------------