添加一个空文件,为什么通过nsfilehangle打不开啊 ,求指导
- (void)viewDidLoad
{
//NSMutableData *data;
NSFileManager *fm = [NSFileManager defaultManager];
NSString *path = [fm currentDirectoryPath];
//NSArray *dirarray;
infile_ = [NSFileHandle fileHandleForReadingAtPath:@"/jia"];
NSMutableString *string = [[NSMutableString alloc]init];
if (infile_ != nil) {
NSMutableArray *temparray = [[NSMutableArray alloc]init];
while ([infile_ offsetInFile] == [infile_ seekToEndOfFile])
{
NSData *tempdata = [infile_ readDataOfLength:1];
string = (NSMutableString *)tempdata;
//[data appendData:tempdata];
[temparray addObject:string];
//data = nil;
}
self.array = temparray;
}
else
{
//dirarray = [fm directoryContentsAtPath:path];
text_.text = path;
}
[super viewDidLoad];
}
[解决办法]
好像路径不太对啊,建议lz调试一下,看看路径是否正确。
另外,我找了一段相关的代码:
NSString *path = [[NSBundle mainBundle] pathForResource:@"webViewContent" ofType:@"html"];
NSFileHandle *readHandle = [NSFileHandle fileHandleForReadingAtPath:path];