- (NSData*)readDataFromFileAtURL:(NSURL*)anURL {
NSString* filePath = [anURL path];
fd = open([filePath UTF8String], O_RDONLY);
if (fd == -1)
return nil;
NSMutableData* theData = [[[NSMutableData alloc] initWithLength:1024]
autorelease];
if (theData) {
void* buffer = [theData mutableBytes];
NSUInteger bufferSize = [theData length];
NSUInteger actualBytes = read(fd, buffer, bufferSize);
if (actualBytes < 1024)
[theData setLength:actualBytes];
}
close(fd);
return theData;
}
Reading the contents of a file using POSIX functions
最新推荐文章于 2024-11-26 18:12:21 发布