FileReference vs File?

爷,独闯天下 提交于 2019-12-14 02:16:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!