Amazon.com Widgets program 16.8
Welcome, Guest. Please login or register.
Did you miss your activation email?
July 28, 2014, 03:19:20 AM
Home Help Search chat Login Register 
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+ Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+ Old Stuff
| |-+ Program Examples
| | |-+ Chapter 16
| | | |-+ program 16.8
Pages: [1] Go Down
Print
Author Topic: program 16.8 (Read 1504 times)
TotalLuck
Full Member
***
Posts: 107



WWW Email




on: February 21, 2009, 06:28:12 PM


Code: (Objective-C)

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSFileHandle *inFile, *outFile;
NSData *buffer;



// Open the file fileA for reading

inFile = [NSFileHandle fileHandleForReadingAtPath: @"fileA"];

if (inFile == nil)
{
NSLog(@"Open of fileA for reading failed!");
return 1;
}

// Now  open outfikle for writing

outFile = [NSFileHandle fileHandleForWritingAtPath: @"fileB"];

if (outFile == nil)
{
NSLog(@" open of fileB for writing failed!");
return 2;
}

// seek to end of  outfile
[outFile seekToEndOfFile];

// read infile and write its content to outfile

buffer = [ inFile readDataToEndOfFile];
[outFile writeData: buffer];

//close the two files

[inFile closeFile];
[outFile closeFile];

// verify its contents

NSLog(@"%@", [NSString stringWithContentsOfFile: @"FileB"
encoding: NSUTF8StringEncoding error: NULL]);

[pool drain];
    return 0;
}
[/pre]
Last Edit: July 28, 2011, 10:37:39 PM by skochan Logged

Apps available on  iTunes store:
"ADACode"  iPhone and iPad versions, "ADAGuidelines" iPhone & iPad versions,  "Rehabilitation Act of 1973" for iPhone
"APokerTimer" now for iPhone http://bit.ly/h1fAJp
Pages: [1] Go Up
Print
Jump to:



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.