How to save a string into file (file.superlongextention) in applicationdirectory and get its real locationon Hard drive (like C:/files/...)?
views:
24answers:
1
+1
A:
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);
Patrick
2010-05-21 21:54:18
Hm... I use Flash builder 4. I wrapped your code (not imports ofcourse) into public function. But when I try to run it it gives me SecurityError: fileWriteResource at flash.filesystem::FileStream/open()
Blender
2010-05-22 11:57:19
So I changed applicationDirectory to userDirectory and it now works...)
Blender
2010-05-22 12:03:25
But how to get rid of "0" in the begining of line?
Blender
2010-05-22 12:14:12
Yes sorry as i said you can't write to applicationDirectory, and i left it in the code, my bad. It 's applicationStorageDirectory in my code. writeUTF write also the length of the string so use writeUTFBytes instead. I have modified the code.
Patrick
2010-05-22 12:39:29