Rella
Rella

Reputation: 66975

How to save a string into file in applicationdirectory and get its real location? (Adobe Air)

How to save a string into file (file.superlongextention) in applicationdirectory and get its real locationon Hard drive (like C:/files/...)?

Upvotes: 0

Views: 4758

Answers (2)

plan9assembler
plan9assembler

Reputation: 2984

but you can save file in Applicationdirectory

var appPath:File = File.applicationDirectory.resolvePath("");
var fromUserPath:File = File.userDirectory.resolvePath(appPath.nativePath);

Thanks to Tanel Teemusk

http://blog.teemusk.com/2011/10/writing-to-applicationdirectory-with-adobe-air/

Upvotes: 1

Patrick
Patrick

Reputation: 15717

For security reason you can't write into the Application directory (for testing you can but it 's realy not recommended).

You can write into the Application Storage directory to store your application data.

  • Use File then FileStream to write your data.
  • To get the path of the file use nativePath.

    import flash.filesystem.File;
    import flash.filesystem.FileStream;
    import flash.filesystem.FileMode;
    import mx.controls.Alert;
    
    // get a file reference to the storage directory
    var file:File=File.applicationStorageDirectory.resolvePath("myfile.withextension");
    
    // create a file stream
    var fs:FileStream=new FileStream();
    
    // open the stream for writting
    fs.open(file, FileMode.WRITE);
    
    // write the string data down to the file
    fs.writeUTFBytes("my string to save");
    
    // ok close the file stream
    fs.close();
    
    // show the path to the file we have saved using Alert
    Alert.show(file.nativePath);
    

Upvotes: 4

Related Questions