如何使用 XMLVM 访问 iPhone 应用程序文档文件夹
在过去的一天左右的时间里,我一直在尝试在 iPhone 应用程序文档目录中创建一个文件。通常,如果我在 Objective-C 中执行此操作,我会使用
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
我需要访问此目录的原因是保存带有某些应用程序设置的 plist 文件(当应用程序需要更新时不应更改)。
我一直将文件存储在普通的 .app 目录中,但是当我尝试保存一些新设置时,我无法覆盖该文件。
这是我用来删除文件的代码
public static Boolean DeleteSettingsFile(){
File f = new File(settingsFile);
if(f.exists())
if(f.delete())
return true;
return false;
}
当尝试从 NSBundle.mainBundle().bundlePath() 文件夹中删除文件时这不起作用
我用此代码得到相同的结果
public static Boolean SaveSettingsFile(String s){
File f = new File(settingsFile);
try {
if(f.createNewFile())
if(NSData.dataWithBytes(s.getBytes()).writeToFile(settingsFile, true))
return true;
}
catch (Exception e){
System.err.println(e.getMessage());
}
return false;
}
这将创建该文件,但随后一次它在那里我只能阅读它的内容。
任何帮助将不胜感激
I have been trying for the past day or so to create a file into the iPhone applications documents directory. Usually if I was doing it in Objective-C I would use
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
The reason that I need access to this directory is to save a plist file with some application settings (that shouldn't change when the app needs updating).
I have been storing the file in the normal .app directory, but from there I cannot overwrite the file when I attempt to save some new settings.
Here is the code I am using to delete the file
public static Boolean DeleteSettingsFile(){
File f = new File(settingsFile);
if(f.exists())
if(f.delete())
return true;
return false;
}
This does not work when trying to delete a file from NSBundle.mainBundle().bundlePath() folder
And I get the same result with this code
public static Boolean SaveSettingsFile(String s){
File f = new File(settingsFile);
try {
if(f.createNewFile())
if(NSData.dataWithBytes(s.getBytes()).writeToFile(settingsFile, true))
return true;
}
catch (Exception e){
System.err.println(e.getMessage());
}
return false;
}
This will create the file, but then once it is there I can only read its contents.
Any help would be appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在最新版本的 XMLVM 中,使用以下代码:
参数与 Objective C 中的完全相同
。请注意,对象 NSSearchPathDirectory、NSSearchPathDomainMask(以及其他对象)也存在。
In the latest version of XMLVM use the following code:
The parameters are exactly the same as in Objective C.
Note that the objects NSSearchPathDirectory, NSSearchPathDomainMask (and others) also exist.