Am writing an application for iphone to read a text file using NSData.
NSFileHandle *fileRead;
// this may lead to crash or memory issue, if the file size is about 10 mb or more
NSData *data = [fileRead readDataOfLength:(entire contents of the file)];
For example, if the file size is 8 kb, we can reading it in 8 iterations by 1kb per cycle.
Before reading the file, how can we find the size of the file contents.so that we can write the code in a optimized way to read the file effectively?
plz give me your suggestions….
The iPhone has all of the standard POSIX APIs, so you can use stat(“file.txt”, &st), where st is a “struct stat”. The “st.st_size” member will give you the file size in bytes.