6

Is it possible to read a file (from my normal file system) into a iPhone App running on the iPhone Simulator?

I understand that the iPhone itself has not got a (user accessible) file system but this is simply for testing and will only ever be run in the simulator.

The file will be a text file that can be edited while the application is running, it will be read every-time a method is called.

Andreas Grech
  • 105,982
  • 98
  • 297
  • 360
Richard Stelling
  • 25,607
  • 27
  • 108
  • 188

6 Answers6

12

Yes, you can, and it doesn't matter where it is. Just give it an absolute path name when you load it (Xcode won't recognize a different working directory when running the simulator).

Jesse Beder
  • 33,081
  • 21
  • 109
  • 146
3

Yes, you can if your file is within your app folder ~/Library/Application Support/iPhone Simulator/User/Applications/ [your app folder] /Documents

CiNN
  • 9,752
  • 6
  • 44
  • 57
  • 1
    It should be noted that this is identical to what you can do on the iPhone, i.e. NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); –  May 01 '09 at 16:20
  • I'm pretty sure you can in general (I just tested it) - why does it have to be in the /Documents folder? – Jesse Beder May 01 '09 at 16:26
  • because it's easier to switch to device – CiNN May 01 '09 at 16:53
0

I personally think that the easiest way would be to enter "file:///" in Safari within the simulator, if thats what your looking for.

iTz Sillohsk8
  • 183
  • 1
  • 2
  • 6
0

It should also be noted that you can do this in reverse -- you can grab the files off your hard drive that your application created in the simulator. This is a good way to check out your results (data, images, whatever) without having to build a data "viewer" into the application.

Amagrammer
  • 6,385
  • 3
  • 28
  • 30
0

FYI 'newer' sds versions will do this... Search for iPad and you will find it. (for obvious reasons I cannot give more details here) good luck.

me i
  • 1
0

No. Your app is running in its own sandbox on the phone. It's not allowed to read or write outside of it.

Edit: I think CiNN is correct. As long as your code stays on the simulator, you shouldn't have problems working with a file on your local drive.

Tim Rupe
  • 4,323
  • 1
  • 22
  • 23
  • But you could make a connection (via TCP) to a little program you write to feed it the data. – MBCook May 01 '09 at 15:56