如何使用 XMLVM 访问 iPhone 应用程序文档文件夹

发布于 2024-11-16 05:19:58 字数 1017 浏览 7 评论 0原文

在过去的一天左右的时间里,我一直在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

简单爱 2024-11-23 05:19:58

在最新版本的 XMLVM 中,使用以下代码:

Foundation.NSSearchPathForDirectoriesInDomains( NSSearchPathDirectory, NSSearchPathDomainMask, expandTilde);

参数与 Objective C 中的完全相同

。请注意,对象 NSSearchPathDirectory、NSSearchPathDomainMask(以及其他对象)也存在。

In the latest version of XMLVM use the following code:

Foundation.NSSearchPathForDirectoriesInDomains( NSSearchPathDirectory, NSSearchPathDomainMask, expandTilde);

The parameters are exactly the same as in Objective C.

Note that the objects NSSearchPathDirectory, NSSearchPathDomainMask (and others) also exist.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文