问题
I want to make a Flash app in which the user can load and save files from and to their local hard drive. While I've often done this in AIR apps using the File
and FileStream
classes, I haven't done so before in an SWF.
From what I know the FileReference
class is used for this, although it seems to have some restrictions due to security risks. I'd like to know what the main differences are between using the FileReference
class and using the File
and FileStream
classes to load and save files.
回答1:
The File
class extends the FileReference
.FileReference
is safe to be used in the FlashPlayer (in the browser) because it won't let you modify the files in the user machine.
If you want to open a file, you need to as for the user to open it for you with: FileReference.browse()
.
To save a file, you need to ask the user to save it: FileReference.save()
With File
class you can open, modify and save files without those dialogs.
Furthermore, the File
class gives you a bunch of useful properties like: File.desktopDirectory
, File.documentsDirectory
and such.
You can check if a file exists with the exists
property and have a much restriction when manipulating file in the user file system.
You can read more about the FileReference and File classes in the docs.
来源:https://stackoverflow.com/questions/16122172/filereference-vs-file