#
import
<foundation foundation.h=
""
>
int
main(
int
argc,
const
char
* argv[])
{
@autoreleasepool
{
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]);
data = [NSData dataWithContentsOfFile:thepath];
NSLog(@
"NSData类方法读取的内容是:%@"
,[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
NSString* content = [NSString stringWithContentsOfFile:thepath encoding:NSUTF8StringEncoding error:nil];
NSLog(@
"NSString类方法读取的内容是:\n%@"
,content);
NSFileHandle* fh = [NSFileHandle fileHandleForReadingAtPath:thepath];
data = [fh readDataToEndOfFile];
NSLog(@
"NSFileHandle实例读取的内容是:\n%@"
, [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
}
return
0
;
}
</foundation>