Thursday, 28 April 2011

flex, air, How to write a file where the application is located


problem

adobe flex4 AS3.0, filestraem (air)
How to write a file where the application is located | the mystery "fileWriteResource" hidden error | how to write files in applicationDirectory (where is not allowed) [tested in windows only]
---
> page by dennis
solution

How to write a file where the application is located
in the follow example, the variable "filename" is String and has as value the the file name without path, i.e.: "sample.txt"
the follow code doesn't work, produces an error "fileWriteResource" that is not even thrown!
    var newFile:File=File.applicationDirectory.resolvePath(filename);
use the follow code:
    var newFile:File=File(File.getRootDirectories()[0]).resolvePath(File.applicationDirectory.nativePath+File.separator+filename);  //I am not kidding... it is working

No comments:

Post a Comment