NSFileHandle *inFile,*outFile;
NSData *buffer;
inFile = [NSFileHandle fileHandleForReadingAtPath:@"jessical2"];
if(inFile == nil){
NSLog(@"open of testfile for reading failed");
return 1;
}
//create the output file fist if necessary
[[NSFileManager defaultManager] createFileAtPath:@"testout" contents:nil attributes:nil];
//now open the out file for writing
outFile = [NSFileHandle fileHandleForWritingAtPath:@"testout"];
if(outFile == nil){
NSLog(@"open of testout for writing failed");
return 2;
}
//truncate the output file since it may contain data
[outFile truncateFileAtOffset:0];
//read the data from inFile and write it to outfile
buffer = [inFile readDataToEndOfFile];
[outFile writeData:buffer];
//close two files
[inFile closeFile];
[outFile closeFile];
//verify the file's contents
NSLog(@"%@",[NSString stringWithContentsOfFile:@"testout" encoding:NSUTF8StringEncoding error:nil]);
*/
/*
NSFileHandle *infile,*outfile;
NSData *buffer;
//open the file1 for reading
infile = [NSFileHandle fileHandleForReadingAtPath:@"file1"];
if(infile == nil){
NSLog(@"open of file1 for reading failed");
return 1;
}
//open the file2 for updating
outfile = [NSFileHandle fileHandleForWritingAtPath:@"file2"];
if(outfile == nil){
NSLog(@"open of the file2 for writing failed");
return 2;
}
//seek to the end of the outfile
[outfile seekToEndOfFile];
//read infile and write its contents to outfile
buffer = [infile readDataToEndOfFile];
[outfile writeData:buffer];
//close two files
[infile closeFile];
[outfile closeFile];
*/
iOS基础一 NSFileHandle
最新推荐文章于 2022-03-14 09:08:40 发布