开发者

How to put\save files into your application directory? (adobe air)

How to put\save files into your application开发者_开发知识库 directory? (adobe air) (code example, please)


It's not recomended but it is possible. Construct your File reference like this:

var pathToFile:String = File.applicationDirectory.resolvePath('file.txt').nativePath;
var someFile:File = new File(pathToFile);


You can't write to your AIR app's Application Directory, it's not allowed. You can however write to a folder that your AIR app creates in the user's directory, called the Application Storage Directory. If you need config files and the like, that's probably the best place to put them. See 'applicationDirectory' in the docs link below:

http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/


@glendon if you try to save directly to applicationDirectory it will indeed throw an error, but it seems you can move the file in the filesystem. i used the code below after yours:

var sourceFile:File = File.applicationStorageDirectory.resolvePath ("file.txt");
var pathToFile:String = File.applicationDirectory.resolvePath ('file.txt').nativePath;
var destination:File = new File (pathToFile);
sourceFile.moveTo (destination, true);

the reason why you 'shouldnt' use the application folder is because not all users have rights to save files in such folder, while everyone will in applicationStorageDirectory.


The accepted answer works!

But if I do this instead:

var vFile = File.applicationDirectory.resolvePath('file.txt');
var vStream = new FileStream();
vStream.open(vFile, FileMode.WRITE);
vStream.writeUTFBytes("Hello World");
vStream.close();

It will give SecurityError: fileWriteResource. However, if I use applicationStorageDirectory instead, the above code will work. It'll only NOT work if it's applicationDirectory. Moreover, Adobe's documentation also says that an AIR app cannot write to its applicationDirectory.

Now, I wonder if it's a bug on Adobe's part that they allow writing to the applicationDirectory using the way suggested by the accepted answer.


try this.

var objFile:File = new File(“file:///”+File.applicationDirectory.resolvePath(strFilePath).nativePath);

the output would be like this…

file:///c:\del\userConf.xml

This will work fine.


If you want write file into ApplicationDirectory, right?

Please don't forget for write for nativeprocess via powershell with registry key for your currect adobe application ( example: C:\Program Files (x86)\AirApp\AirApp.exe with RunAsAdmin )

  1. nativeprocess saves new registry file
  2. AirApp will restarts into RunASAdmin
  3. AirApp can be writable possible with file :)

Don't worry!

I know that trick like sometimes application write frist via registry file and calls powershell by writing nativeprocess into registry file into registry structures.

Look like my suggestion from adobe system boards / forum was better than access problem with writing stream with file :)

I hope you because you know my nice trick with nativeprocess via powershell + regedit /s \AirApp.reg and AirApp changes into administratived AirApp than it works fine with Administratived mode :) Than your solution should write and you try - Make sure for your writing process by AirApp.


this function gives your current air application folder which bypasses the security problem:

function SWFName(): String {
        var swfName: String;
        var mySWF = new File(this.loaderInfo.url).nativePath;
        swfName= this.loaderInfo.loaderURL;
        swfName = swfName.slice(swfName.lastIndexOf("/") + 1); // Extract the filename from the url
        swfName = new URLVariables("path=" + swfName).path; // this is a hack to decode URL-encoded values
        mySWF = mySWF.replace(swfName, "");
        return mySWF;
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜