1

テキストファイルからテキストを読み取ろうとしています。これを行うには、stringWithContentsOfFile を使用しました。

pathName        = [[NSBundle mainBundle] pathForResource:sample ofType:@"txt"];
entireContent   = [NSString stringWithContentsOfFile:pathName encoding:NSUTF8StringEncoding error:NULL];
entireChapter   = [entireContent substringWithRange:sourceRange];

弦を速くする別の方法を持っている人はいますか?

4

1 に答える 1

1

NSFileHandle を使用できます。

NSFileHandle *fileHandler = [NSFileHandle fileHandleForUpdatingAtPath:filePath];
[fileHandler seekToFileOffset:10];
NSData *data = [fileHandler readDataOfLength:10];
[fileHandler closeFile];

これを試すことができます。その後、nsdata を文字列に変換できます。

于 2011-09-09T09:42:36.970 に答える