本文介绍了Xcode:模拟器Iphone的目录文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在文件file.txt中写一个字符串:我的项目中的这个文件(对于Iphone)在资源中;我尝试在这个文件中写一个字符串,但它不起作用,我显示我的代码。

  NSArray * paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory,NSUserDomainMask,YES); 
NSString * documentsDirectory = [paths objectAtIndex:0];
NSString * filePath = [documentsDirectory stringByAppendingPathComponent:@file.txt];
NSError *错误;
[outputString writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:& error];

我想使用模拟器xcode在这个文件中编写,而不是使用设备

解决方案

我不知道你是否能够写入你的软件包,但你可以在你的文档目录中,而不是你的代码。为什么不尝试这个?



使用相同的代码,你会发现你的文件在:



/ Users / YOURUSER /图书馆/应用程序支持/ iPhone模拟器/ IOSVERSION /应用程序/ APPID /Documents/file.txt


i want to write a string in a file "file.txt": this file in my project (for Iphone) is inside Resources; I try to write a string in this file but it don't work, I show my code.

 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath =  [documentsDirectory stringByAppendingPathComponent:@"file.txt"];
NSError *error;
[outputString writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:&error];

I want write in this file with simulator xcode, not with device

解决方案

I'm not sure if you are able to write in your bundle, but you can in your Documents directory instead as your code does. Why don't you try this?

Use the same code and you will find your file in:

/Users/YOURUSER/Library/Application Support/iPhone Simulator/IOSVERSION/Applications/APPID/Documents/file.txt

这篇关于Xcode:模拟器Iphone的目录文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 06:57
查看更多