//第一種方法: NSFileManager實例方法讀取數據NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES);NSString* thepath = [paths lastObject];thepath = [thepath stringByAppendingPathComponent:@"fd_list.txt"];
NSLog(@"桌面目錄:%@", thepath);
NSFileManager* fm = [NSFileManager defaultManager];NSData* data = [[NSData alloc] init];data = [fm contentsAtPath:thepath];NSLog(@"%@",[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);//第二種方法: NSData類方法讀取數據data = [NSData dataWithContentsOfFile:thepath];NSLog(@"NSData類方法讀取的內容是:%@",[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);//第三種方法: NSString類方法讀取內容NSString* content = [NSString stringWithContentsOfFile:thepath encoding:NSUTF8StringEncoding error:nil];NSLog(@"NSString類方法讀取的內容是:\n%@",content);//第四種方法: NSFileHandle實例方法讀取內容NSFileHandle* fh = [NSFileHandle fileHandleForReadingAtPath:thepath];data = [fh readDataToEndOfFile];NSLog(@"NSFileHandle實例讀取的內容是:\n%@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);}
加載bund里面的文件
? ??NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"LMSetting" ofType:@"plist"];
?