Cover by Joe Conway, Aaron Hillegass

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

For the More Curious: Reading and Writing to the Filesystem

In addition to archiving and NSData’s binary read and write methods, there are a few more methods for transferring data to and from the filesystem. One of them, Core Data, is coming up in Chapter 16. A couple of others are worth mentioning here.

You have access to the standard file I/O functions from the C library. These functions look like this:

F​I​L​E​ ​*​i​n​F​i​l​e​ ​=​ ​f​o​p​e​n​(​"​t​e​x​t​f​i​l​e​"​,​ ​"​r​t​"​)​;​ c​h​a​r​ ​*​b​u​f​f​e​r​ ​=​ ​m​a​l​l​o​c​(​s​o​m​e​S​i​z​e​)​;​ f​r​e​a​d​(​b​u​f​f​e​r​,​ ​b​y​t​e​C​o​u​n​t​,​ ​1​,​ ​i​n​F​i​l​e​)​;​ F​I​L​E​ ​*​o​u​t​F​i​l​e​ ​=​ ​f​o​p​e​n​(​"​b​i​n​a​r​y​f​i​l​e​"​,​ ​"​w​"​)​;​ f​w​r​i​t​e​(​b​u​f​f​e​r​,​ ​b​y​t​e​C​o​u​n​t​,​ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required