[[NSFileManager defaultManager]
changeCurrentDirectoryPath:[[NSBundle mainBundle] resourcePath]];
文件添加,显示,导航等等等等等等等!
想要的,想学的都来下载一下吧!
//加载文件内容
- (void) loadFileContentsIntoTextView {
// open a stream to filePath
NSInputStream*inputStream = [[NSInputStreamalloc]
initWithFileAtPath: filePath];
[inputStream open];
// read and dump to NSTextView
NSInteger maxLength = 128;
uint8_treadBuffer [maxLength];//typedef unsigned char :uint8_t;
BOOL endOfStreamReached = NO;
// NOTE: this tight loop will block until stream ends
while (! endOfStreamReached) {
NSInteger bytesRead = [inputStream read: readBuffer
maxLength:maxLength];
if (bytesRead == 0) {
endOfStreamReached = YES;
} else if (bytesRead == -1) {
// TODO - should have an error dialog
endOfStreamReached = YES;
} else {
NSString *readBufferString =
[[NSStringalloc]
initWithBytesNoCopy: readBuffer
length: bytesRead
encoding: NSUTF8StringEncoding
freeWhenDone: NO];
[self appendTextToView: readBufferString];
[readBufferString release];
}
} // while ! endOfStreamReached
[inputStream close];
[inputStream release];
}