问题
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.
回答1:
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).
回答2:
Yes, you can if your file is within your app folder ~/Library/Application Support/iPhone Simulator/User/Applications/ [your app folder] /Documents
回答3:
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.
回答4:
I personally think that the easiest way would be to enter "file:///" in Safari within the simulator, if thats what your looking for.
回答5:
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.
回答6:
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.
来源:https://stackoverflow.com/questions/811924/reading-a-file-from-a-hard-drive-in-iphone-simulator