NSString * path = [path lastPathCompoment];获取相对路径
NSArray * directory = [[NSFileManager defaunltManager] directoryContentsAtPath:path];
获取目录下内容;
NSString*PATH2 = NSHomeDirectory();得到应用程序主目录;
BOOL myPathIsDir;
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:selectedPath isDirectory &myPathIsDir];
判断当前路径是目录还是文件;
-(void)updataFileOverview{
NSString * fileName = [self.filePath lastPathCompnent];
NSDataForMatter *dateMatter = [[NSDataForMatter alloc] init];
[dataForMatter setDataStyle: NSDateForMatterMediumStyle];
[dataForMatter setTimeStyle:NSDateForMatterNoStyle];
NSNumberFormatter * numberMatter = [[NSNumberFormatter alloc] init];
[numberMatter setPositiveForMat:@"#,##0.## bytes"];
NSDictionary *fileAttributes =[ [NSfileManager defaultManager] fileAttributesAtPath:self.filePath traverseLink:YES];
}
异步读文件
{
NSInputStream * inputStream = [[NSInputStream alloc] initWithFileAtPath:filepath];
[inputStrem setDelegate:self];
[inputStream scheduleInputRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];//该调用指示当前线程的运行循环成为处理检查流状态的那个循环
[inputStrem open];
[inputStream release];
}
代理方法:
-(void)strem:(NSStrem *)theStream handleEvent:(NSStreamEvent)streamEvent{
NSInputStream *inputStream = (NSInputStream*) theStream;
switch(streamEvent){
case NSStremEventHasBytesAvailable:{有字节可读事件
NSInteger maxLengh = 128;
unit8_t readBuffer [maxLengh];
NSInteger bytesRead = [inputStream read:readBuffer maxLengh:maxLengh];
if(bytesRead>0)
{NSString * bufferString = [[NSString alloc] initWithBytesNoCopy:radBuffer length: bytesRead ecoding:NSUTF8StringEcoding freeWhenDone:NO];
[self appendTextToView:bufferString];
[bufferString release];
}break;
}
case
}
}