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

时间:2023-01-13 20:55:38

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

我一直在尝试将过去一天左右的文件创建到iPhone应用程序文档目录中。通常,如果我在Objective-C中这样做,我会使用

NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

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).

我需要访问此目录的原因是保存带有一些应用程序设置的plist文件(当应用程序需要更新时不应该更改)。

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.

我一直在将文件存储在正常的.app目录中,但是当我尝试保存一些新设置时,我无法覆盖该文件。

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

尝试从NSBundle.mainBundle()。bundlePath()文件夹中删除文件时,这不起作用

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

任何帮助,将不胜感激

1 个解决方案

#1


0  

In the latest version of XMLVM use the following code:

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

Foundation.NSSearchPathForDirectoriesInDomains( NSSearchPathDirectory, NSSearchPathDomainMask, expandTilde);

The parameters are exactly the same as in Objective C.

参数与Objective C中的参数完全相同。

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

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

#1


0  

In the latest version of XMLVM use the following code:

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

Foundation.NSSearchPathForDirectoriesInDomains( NSSearchPathDirectory, NSSearchPathDomainMask, expandTilde);

The parameters are exactly the same as in Objective C.

参数与Objective C中的参数完全相同。

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

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