Widgets program 16.8
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 29, 2015, 08:52:13 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
Author Topic: program 16.8 (Read 1730 times)
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;
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

Pages: [1] Go Up
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 All rights reserved.