用于 Adobe® Flash® Platform 的 ActionScript® 3.0 参考
主页  |  隐藏包列表和类列表 |   |   |  新增内容  |  索引  |  附录  |  为什么显示为英语?
过滤条件: AIR 30.0 和更早版本, Flash Player 30.0 和更早版本, Flash Lite 4
Flex 4.6 和更早版本, Flash Pro CS6 和更早版本
隐藏过滤条件
flash.filesystem 

File  - AS3

x

顶级
adobe.utils
air.desktop
air.net
air.update
air.update.events
coldfusion.air
coldfusion.air.errors
coldfusion.air.events
coldfusion.service
coldfusion.service.events
coldfusion.service.mxml
com.adobe.acm.solutions.authoring.domain.extensions
com.adobe.acm.solutions.ccr.domain.extensions
com.adobe.consulting.pst.vo
com.adobe.dct.component
com.adobe.dct.component.datadictionary
com.adobe.dct.component.datadictionaryElement
com.adobe.dct.component.dataElementsPanel
com.adobe.dct.component.toolbars
com.adobe.dct.event
com.adobe.dct.exp
com.adobe.dct.model
com.adobe.dct.service
com.adobe.dct.service.provider
com.adobe.dct.transfer
com.adobe.dct.util
com.adobe.dct.view
com.adobe.ep.taskmanagement.domain
com.adobe.ep.taskmanagement.event
com.adobe.ep.taskmanagement.filter
com.adobe.ep.taskmanagement.services
com.adobe.ep.taskmanagement.util
com.adobe.ep.ux.attachmentlist.component
com.adobe.ep.ux.attachmentlist.domain
com.adobe.ep.ux.attachmentlist.domain.events
com.adobe.ep.ux.attachmentlist.domain.renderers
com.adobe.ep.ux.attachmentlist.skin
com.adobe.ep.ux.attachmentlist.skin.renderers
com.adobe.ep.ux.content.event
com.adobe.ep.ux.content.factory
com.adobe.ep.ux.content.handlers
com.adobe.ep.ux.content.managers
com.adobe.ep.ux.content.model.asset
com.adobe.ep.ux.content.model.preview
com.adobe.ep.ux.content.model.relation
com.adobe.ep.ux.content.model.search
com.adobe.ep.ux.content.model.toolbar
com.adobe.ep.ux.content.search
com.adobe.ep.ux.content.services
com.adobe.ep.ux.content.services.load
com.adobe.ep.ux.content.services.permissions
com.adobe.ep.ux.content.services.preview
com.adobe.ep.ux.content.services.providers
com.adobe.ep.ux.content.services.query
com.adobe.ep.ux.content.services.relationships
com.adobe.ep.ux.content.services.search.lccontent
com.adobe.ep.ux.content.services.version
com.adobe.ep.ux.content.view
com.adobe.ep.ux.content.view.components.activate
com.adobe.ep.ux.content.view.components.grid
com.adobe.ep.ux.content.view.components.grid.hover
com.adobe.ep.ux.content.view.components.grid.hover.component
com.adobe.ep.ux.content.view.components.grid.renderers
com.adobe.ep.ux.content.view.components.relationships
com.adobe.ep.ux.content.view.components.review
com.adobe.ep.ux.content.view.components.search.renderers
com.adobe.ep.ux.content.view.components.searchpod
com.adobe.ep.ux.content.view.components.toolbar
com.adobe.ep.ux.content.view.components.toolbar.controlRenderers
com.adobe.ep.ux.content.view.components.version
com.adobe.ep.ux.documentsubmit.component
com.adobe.ep.ux.documentsubmit.domain
com.adobe.ep.ux.documentsubmit.skin
com.adobe.ep.ux.taskaction.component
com.adobe.ep.ux.taskaction.domain
com.adobe.ep.ux.taskaction.domain.events
com.adobe.ep.ux.taskaction.skin
com.adobe.ep.ux.taskdetails.component
com.adobe.ep.ux.taskdetails.domain
com.adobe.ep.ux.taskdetails.skin
com.adobe.ep.ux.tasklist.component
com.adobe.ep.ux.tasklist.domain
com.adobe.ep.ux.tasklist.skin
com.adobe.ep.ux.webdocumentviewer.domain
com.adobe.exm.expression
com.adobe.exm.expression.error
com.adobe.exm.expression.event
com.adobe.exm.expression.impl
com.adobe.fiber.runtime.lib
com.adobe.fiber.services
com.adobe.fiber.services.wrapper
com.adobe.fiber.styles
com.adobe.fiber.util
com.adobe.fiber.valueobjects
com.adobe.gravity.binding
com.adobe.gravity.context
com.adobe.gravity.flex.bundleloader
com.adobe.gravity.flex.progress
com.adobe.gravity.flex.serviceloader
com.adobe.gravity.framework
com.adobe.gravity.init
com.adobe.gravity.service.bundleloader
com.adobe.gravity.service.logging
com.adobe.gravity.service.manifest
com.adobe.gravity.service.progress
com.adobe.gravity.tracker
com.adobe.gravity.ui
com.adobe.gravity.utility
com.adobe.gravity.utility.async
com.adobe.gravity.utility.error
com.adobe.gravity.utility.events
com.adobe.gravity.utility.factory
com.adobe.gravity.utility.flex.async
com.adobe.gravity.utility.logging
com.adobe.gravity.utility.message
com.adobe.gravity.utility.sequence
com.adobe.gravity.utility.url
com.adobe.guides.control
com.adobe.guides.domain
com.adobe.guides.i18n
com.adobe.guides.spark.components.skins
com.adobe.guides.spark.components.skins.mx
com.adobe.guides.spark.headers.components
com.adobe.guides.spark.headers.skins
com.adobe.guides.spark.layouts.components
com.adobe.guides.spark.layouts.skins
com.adobe.guides.spark.navigators.components
com.adobe.guides.spark.navigators.renderers
com.adobe.guides.spark.navigators.skins
com.adobe.guides.spark.util
com.adobe.guides.spark.wrappers.components
com.adobe.guides.spark.wrappers.skins
com.adobe.guides.submit
com.adobe.icc.dc.domain
com.adobe.icc.dc.domain.factory
com.adobe.icc.editors.events
com.adobe.icc.editors.handlers
com.adobe.icc.editors.managers
com.adobe.icc.editors.model
com.adobe.icc.editors.model.config
com.adobe.icc.editors.model.el
com.adobe.icc.editors.model.el.operands
com.adobe.icc.editors.model.el.operators
com.adobe.icc.enum
com.adobe.icc.external.dc
com.adobe.icc.obj
com.adobe.icc.services
com.adobe.icc.services.category
com.adobe.icc.services.config
com.adobe.icc.services.download
com.adobe.icc.services.export
com.adobe.icc.services.external
com.adobe.icc.services.formbridge
com.adobe.icc.services.fragmentlayout
com.adobe.icc.services.layout
com.adobe.icc.services.letter
com.adobe.icc.services.locator
com.adobe.icc.services.module
com.adobe.icc.services.render
com.adobe.icc.services.submit
com.adobe.icc.services.user
com.adobe.icc.token
com.adobe.icc.vo
com.adobe.icc.vo.render
com.adobe.icomm.assetplacement.controller
com.adobe.icomm.assetplacement.controller.utils
com.adobe.icomm.assetplacement.data
com.adobe.icomm.assetplacement.model
com.adobe.livecycle.assetmanager.client
com.adobe.livecycle.assetmanager.client.event
com.adobe.livecycle.assetmanager.client.handler
com.adobe.livecycle.assetmanager.client.managers
com.adobe.livecycle.assetmanager.client.model
com.adobe.livecycle.assetmanager.client.model.cms
com.adobe.livecycle.assetmanager.client.service
com.adobe.livecycle.assetmanager.client.service.search
com.adobe.livecycle.assetmanager.client.service.search.cms
com.adobe.livecycle.assetmanager.client.utils
com.adobe.livecycle.content
com.adobe.livecycle.rca.model
com.adobe.livecycle.rca.model.constant
com.adobe.livecycle.rca.model.document
com.adobe.livecycle.rca.model.participant
com.adobe.livecycle.rca.model.reminder
com.adobe.livecycle.rca.model.stage
com.adobe.livecycle.rca.service
com.adobe.livecycle.rca.service.core
com.adobe.livecycle.rca.service.core.delegate
com.adobe.livecycle.rca.service.process
com.adobe.livecycle.rca.service.process.delegate
com.adobe.livecycle.rca.token
com.adobe.livecycle.ria.security.api
com.adobe.livecycle.ria.security.service
com.adobe.mosaic.layouts
com.adobe.mosaic.layouts.dragAndDrop
com.adobe.mosaic.layouts.interfaces
com.adobe.mosaic.mxml
com.adobe.mosaic.om.constants
com.adobe.mosaic.om.events
com.adobe.mosaic.om.impl
com.adobe.mosaic.om.interfaces
com.adobe.mosaic.skinning
com.adobe.mosaic.sparklib.editors
com.adobe.mosaic.sparklib.optionMenu
com.adobe.mosaic.sparklib.scrollableMenu
com.adobe.mosaic.sparklib.scrollableMenu.skins
com.adobe.mosaic.sparklib.tabLayout
com.adobe.mosaic.sparklib.tabLayout.events
com.adobe.mosaic.sparklib.tabLayout.layouts
com.adobe.mosaic.sparklib.tabLayout.skins
com.adobe.mosaic.sparklib.text
com.adobe.mosaic.sparklib.util
com.adobe.solutions.acm.authoring.presentation
com.adobe.solutions.acm.authoring.presentation.actionbar
com.adobe.solutions.acm.authoring.presentation.common
com.adobe.solutions.acm.authoring.presentation.events
com.adobe.solutions.acm.authoring.presentation.fragment
com.adobe.solutions.acm.authoring.presentation.letter
com.adobe.solutions.acm.authoring.presentation.letter.data
com.adobe.solutions.acm.authoring.presentation.preview
com.adobe.solutions.acm.authoring.presentation.rte
com.adobe.solutions.acm.ccr.presentation
com.adobe.solutions.acm.ccr.presentation.contentcapture
com.adobe.solutions.acm.ccr.presentation.contentcapture.events
com.adobe.solutions.acm.ccr.presentation.contentcapture.preview
com.adobe.solutions.acm.ccr.presentation.datacapture
com.adobe.solutions.acm.ccr.presentation.datacapture.renderers
com.adobe.solutions.acm.ccr.presentation.pdf
com.adobe.solutions.exm
com.adobe.solutions.exm.authoring
com.adobe.solutions.exm.authoring.components.controls
com.adobe.solutions.exm.authoring.components.toolbars
com.adobe.solutions.exm.authoring.domain
com.adobe.solutions.exm.authoring.domain.expression
com.adobe.solutions.exm.authoring.domain.impl
com.adobe.solutions.exm.authoring.domain.method
com.adobe.solutions.exm.authoring.domain.variable
com.adobe.solutions.exm.authoring.enum
com.adobe.solutions.exm.authoring.events
com.adobe.solutions.exm.authoring.model
com.adobe.solutions.exm.authoring.renderer
com.adobe.solutions.exm.authoring.view
com.adobe.solutions.exm.expression
com.adobe.solutions.exm.impl
com.adobe.solutions.exm.impl.method
com.adobe.solutions.exm.method
com.adobe.solutions.exm.mock
com.adobe.solutions.exm.mock.method
com.adobe.solutions.exm.runtime
com.adobe.solutions.exm.runtime.impl
com.adobe.solutions.exm.variable
com.adobe.solutions.prm.constant
com.adobe.solutions.prm.domain
com.adobe.solutions.prm.domain.factory
com.adobe.solutions.prm.domain.impl
com.adobe.solutions.prm.domain.manager
com.adobe.solutions.prm.presentation.asset
com.adobe.solutions.prm.presentation.constant
com.adobe.solutions.prm.presentation.document
com.adobe.solutions.prm.presentation.event
com.adobe.solutions.prm.presentation.file
com.adobe.solutions.prm.presentation.project
com.adobe.solutions.prm.presentation.team
com.adobe.solutions.prm.presentation.util
com.adobe.solutions.prm.service
com.adobe.solutions.prm.services.impl
com.adobe.solutions.prm.vo
com.adobe.solutions.rca.constant
com.adobe.solutions.rca.domain
com.adobe.solutions.rca.domain.common
com.adobe.solutions.rca.domain.factory
com.adobe.solutions.rca.domain.impl
com.adobe.solutions.rca.domain.impl.manager
com.adobe.solutions.rca.domain.manager
com.adobe.solutions.rca.presentation
com.adobe.solutions.rca.presentation.comment
com.adobe.solutions.rca.presentation.constant
com.adobe.solutions.rca.presentation.event
com.adobe.solutions.rca.presentation.gantt
com.adobe.solutions.rca.presentation.gantt.ruler
com.adobe.solutions.rca.presentation.template
com.adobe.solutions.rca.presentation.template.audit
com.adobe.solutions.rca.presentation.template.definition
com.adobe.solutions.rca.presentation.template.documents
com.adobe.solutions.rca.presentation.template.stages
com.adobe.solutions.rca.presentation.util
com.adobe.solutions.rca.service
com.adobe.solutions.rca.services.impl
com.adobe.solutions.rca.vo
com.adobe.solutions.rca.vo.um
com.adobe.viewsource
fl.accessibility
fl.containers
fl.controls
fl.controls.dataGridClasses
fl.controls.listClasses
fl.controls.progressBarClasses
fl.core
fl.data
fl.display
fl.events
fl.ik
fl.lang
fl.livepreview
fl.managers
fl.motion
fl.motion.easing
fl.rsl
fl.text
fl.transitions
fl.transitions.easing
fl.video
flash.accessibility
flash.concurrent
flash.crypto
flash.data
flash.desktop
flash.display
flash.display3D
flash.display3D.textures
flash.errors
flash.events
flash.external
flash.filesystem
flash.filters
flash.geom
flash.globalization
flash.html
flash.media
flash.net
flash.net.dns
flash.net.drm
flash.notifications
flash.permissions
flash.printing
flash.profiler
flash.sampler
flash.security
flash.sensors
flash.system
flash.text
flash.text.engine
flash.text.ime
flash.ui
flash.utils
flash.xml
flashx.textLayout
flashx.textLayout.compose
flashx.textLayout.container
flashx.textLayout.conversion
flashx.textLayout.edit
flashx.textLayout.elements
flashx.textLayout.events
flashx.textLayout.factory
flashx.textLayout.formats
flashx.textLayout.operations
flashx.textLayout.utils
flashx.undo
ga.controls
ga.layouts
ga.model
ga.uiComponents
ga.util
ga.views
ga.wrappers
lc.foundation
lc.foundation.domain
lc.foundation.events
lc.foundation.ui
lc.foundation.util
lc.preloader
lc.procmgmt
lc.procmgmt.commands
lc.procmgmt.domain
lc.procmgmt.events
lc.procmgmt.formbridge
lc.procmgmt.impl
lc.procmgmt.ui.attachments
lc.procmgmt.ui.controls
lc.procmgmt.ui.controls.card
lc.procmgmt.ui.controls.renderer
lc.procmgmt.ui.help
lc.procmgmt.ui.layout
lc.procmgmt.ui.presentationmodel
lc.procmgmt.ui.process
lc.procmgmt.ui.search
lc.procmgmt.ui.startpoint
lc.procmgmt.ui.task
lc.procmgmt.ui.task.form
lc.procmgmt.ui.task.form.commands
lc.procmgmt.ui.tracking
mx.accessibility
mx.automation
mx.automation.air
mx.automation.delegates
mx.automation.delegates.advancedDataGrid
mx.automation.delegates.charts
mx.automation.delegates.containers
mx.automation.delegates.controls
mx.automation.delegates.controls.dataGridClasses
mx.automation.delegates.controls.fileSystemClasses
mx.automation.delegates.core
mx.automation.delegates.flashflexkit
mx.automation.events
mx.binding
mx.binding.utils
mx.charts
mx.charts.chartClasses
mx.charts.effects
mx.charts.effects.effectClasses
mx.charts.events
mx.charts.renderers
mx.charts.series
mx.charts.series.items
mx.charts.series.renderData
mx.charts.styles
mx.collections
mx.collections.errors
mx.containers
mx.containers.accordionClasses
mx.containers.dividedBoxClasses
mx.containers.errors
mx.containers.utilityClasses
mx.controls
mx.controls.advancedDataGridClasses
mx.controls.dataGridClasses
mx.controls.listClasses
mx.controls.menuClasses
mx.controls.olapDataGridClasses
mx.controls.scrollClasses
mx.controls.sliderClasses
mx.controls.textClasses
mx.controls.treeClasses
mx.controls.videoClasses
mx.core
mx.core.windowClasses
mx.data
mx.data.crypto
mx.data.errors
mx.data.events
mx.data.messages
mx.data.mxml
mx.data.offline.errors
mx.data.utils
mx.effects
mx.effects.easing
mx.effects.effectClasses
mx.events
mx.filters
mx.flash
mx.formatters
mx.geom
mx.graphics
mx.graphics.codec
mx.graphics.shaderClasses
mx.logging
mx.logging.errors
mx.logging.targets
mx.managers
mx.messaging
mx.messaging.channels
mx.messaging.config
mx.messaging.errors
mx.messaging.events
mx.messaging.management
mx.messaging.messages
mx.modules
mx.netmon
mx.olap
mx.olap.aggregators
mx.preloaders
mx.printing
mx.resources
mx.rpc
mx.rpc.events
mx.rpc.http
mx.rpc.http.mxml
mx.rpc.livecycle
mx.rpc.mxml
mx.rpc.remoting
mx.rpc.remoting.mxml
mx.rpc.soap
mx.rpc.soap.mxml
mx.rpc.wsdl
mx.rpc.xml
mx.skins
mx.skins.halo
mx.skins.spark
mx.skins.wireframe
mx.skins.wireframe.windowChrome
mx.states
mx.styles
mx.utils
mx.validators
org.osmf.containers
org.osmf.display
org.osmf.elements
org.osmf.events
org.osmf.layout
org.osmf.logging
org.osmf.media
org.osmf.metadata
org.osmf.net
org.osmf.net.dvr
org.osmf.net.httpstreaming
org.osmf.net.metrics
org.osmf.net.qos
org.osmf.net.rtmpstreaming
org.osmf.net.rules
org.osmf.traits
org.osmf.utils
spark.accessibility
spark.automation.delegates
spark.automation.delegates.components
spark.automation.delegates.components.gridClasses
spark.automation.delegates.components.mediaClasses
spark.automation.delegates.components.supportClasses
spark.automation.delegates.skins.spark
spark.automation.events
spark.collections
spark.components
spark.components.calendarClasses
spark.components.gridClasses
spark.components.mediaClasses
spark.components.supportClasses
spark.components.windowClasses
spark.core
spark.effects
spark.effects.animation
spark.effects.easing
spark.effects.interpolation
spark.effects.supportClasses
spark.events
spark.filters
spark.formatters
spark.formatters.supportClasses
spark.globalization
spark.globalization.supportClasses
spark.layouts
spark.layouts.supportClasses
spark.managers
spark.modules
spark.preloaders
spark.primitives
spark.primitives.supportClasses
spark.skins
spark.skins.mobile
spark.skins.mobile.supportClasses
spark.skins.spark
spark.skins.spark.mediaClasses.fullScreen
spark.skins.spark.mediaClasses.normal
spark.skins.spark.windowChrome
spark.skins.wireframe
spark.skins.wireframe.mediaClasses
spark.skins.wireframe.mediaClasses.fullScreen
spark.transitions
spark.utils
spark.validators
spark.validators.supportClasses
xd.core.axm.enterprise.view.components
xd.core.axm.enterprise.view.skins
xd.core.axm.view.components
xd.core.axm.view.components.support

语言元素

全局常量
全局函数
运算符
语句、关键字和指令
特殊类型

附录

新增内容
编译器错误
编译器警告
运行时错误
迁移到 ActionScript 3
支持的字符集
仅适用于 MXML 的标签
Motion XML 元素
Timed Text 标记
不推荐使用的元素的列表
AccessibilityImplementation 常量
如何使用 ActionScript 示例
法律声明
flash.filesystem
public class File
继承File Inheritance FileReference Inheritance EventDispatcher Inheritance Object

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

File 对象表示文件或目录的路径。这可以是现有的文件或目录,也可以是尚不存在的文件或目录(例如,它可以表示希望创建的文件或目录的路径)。

File 类具有许多属性和方法,用于获取有关文件系统的信息和用于执行各种操作(如复制文件和目录)。

可以与 FileStream 类一起使用 File 对象来读取和写入文件。

File 类扩展 FileReference 类。Flash® Player 和 Adobe® AIR® 都提供了 FileReference 类,它表示指向文件的指针,但 File 类添加了一些由于安全原因,不在 Flash Player 中(在浏览器中运行的 SWF 中)公开的属性和方法。

File 类包含一些静态属性,供引用常用目录位置。这些静态属性包括:

  • File.applicationStorageDirectory — 每个已安装的 AIR 应用程序独有的存储目录
  • File.applicationDirectory — 安装应用程序的只读目录(其中包括所有已安装的资源)
  • File.desktopDirectory — 用户的桌面目录
  • File.documentsDirectory — 用户的文档目录
  • File.userDirectory — 用户目录

这些属性的值在不同操作系统中均有意义。例如,在 Mac OS、Linux 和 Windows 上,用户桌面目录的本机路径各不相同。但是,File.desktopDirectory 属性在其中每个平台上,都会指向正确的桌面目录路径。要编写可以跨平台正常工作的应用程序,在需要引用应用程序使用的其他文件时,请以这些属性为基础,然后使用 resolvePath() 方法来完善路径。例如,此代码会指向应用程序存储目录中的 preferences.xml 文件:

 var prefsFile:File = File.applicationStorageDirectory;
  prefsFile = prefsFile.resolvePath("preferences.xml");

如果引用文件时,使用了文本常量形式的本机路径,它将只在一个平台上有效。例如,下面的 File 对象仅在 Windows 上有效:

new File("C:\Documents and Settings\joe\My Documents\test.txt")

应用程序存储目录非常有用。它为 AIR 应用程序提供了专用存储目录。此存储目录由 File.applicationStorageDirectory 属性定义。请注意,在 Mac OS 平台上,此位置在 AIR 3.2 和 AIR 3.3 之间发生了变化。

不要在应用程序目录(AIR 应用程序的安装位置)中添加或删除内容。否则会损坏 AIR 应用程序,应用程序签名也将失效。AIR 默认不允许写入应用程序目录,因为该目录并非对所有操作系统上的所有用户帐户均为可写目录。应用程序存储目录用于写入内部应用程序文件。文档目录用于写入用户希望能在应用程序之外使用的文件,如已编辑的图片或文本文件。

相关 API 元素



公共属性
 属性由以下参数定义
      applicationDirectory : File
[静态] [只读] 包含应用程序已安装文件的文件夹。
File
      applicationStorageDirectory : File
[静态] [只读] 应用程序的专用存储目录。
File
      cacheDirectory : File
[静态] [只读] 应用程序的缓存目录。
File
 Inheritedconstructor : Object
对类对象或给定对象实例的构造函数的引用。
Object
 InheritedcreationDate : Date
[只读] 本地磁盘上文件的创建日期。
FileReference
 Inheritedcreator : String
[只读] 文件的 Macintosh 创建者类型,此类型仅用于 Mac OS X 之前的 Mac OS 版本中。
FileReference
 Inheriteddata : ByteArray
[只读] 成功调用 load() 方法之后代表所加载文件中的数据的 ByteArray 对象。
FileReference
      desktopDirectory : File
[静态] [只读] 用户桌面目录。
File
      documentsDirectory : File
[静态] [只读] 用户文档目录。
File
      downloaded : Boolean
表示是否已(从 Internet)下载参考文件或目录。
File
      exists : Boolean
[只读] 表示引用的文件或目录是否存在。
File
 Inherited    extension : String
[只读] 文件扩展名。
FileReference
      icon : Icon
[只读] 包含为文件定义的图标的 Icon 对象。
File
      isDirectory : Boolean
[只读] 表示是否为对目录的引用。
File
      isHidden : Boolean
[只读] 表示引用的文件或目录是否为“隐藏”。如果引用的文件或目录是隐藏的,则该值为 true;否则为 false。
File
      isPackage : Boolean
[只读] 表示引用的目录是否为包。
File
      isSymbolicLink : Boolean
[只读] 表示引用是否为符号链接。
File
      lineEnding : String
[静态] [只读] 主机操作系统使用的行结束字符序列。
File
 InheritedmodificationDate : Date
[只读] 本地磁盘上文件的上一次修改日期。
FileReference
 Inheritedname : String
[只读] 本地磁盘上的文件的名称。
FileReference
      nativePath : String
采用主机操作系统表示形式的完整路径。
File
      parent : File
[只读] 包含此 File 对象引用的文件或目录的目录。
File
      permissionStatus : String
[静态] [只读] 确定应用程序是否已被授予文件系统访问权限。
File
      preventBackup : Boolean
指示运行时是否阻止此 File 对象备份到云。
File
      separator : String
[静态] [只读] 主机操作系统的路径组件分隔符。
File
 Inheritedsize : Number
[只读] 本地磁盘上文件的大小(以字节为单位)。
FileReference
      spaceAvailable : Number
[只读] 可用于在此 File 位置使用的空间,以字节为单位。
File
      systemCharset : String
[静态] [只读] 主机操作系统使用的默认编码。
File
 Inheritedtype : String
[只读] 文件类型。
FileReference
      url : String
此文件路径的 URL。
File
      userDirectory : File
[静态] [只读] 用户目录。
File
公共方法
 方法由以下参数定义
  
    File(path:String = null)
File 类的构造函数。
File
 Inherited
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
使用 EventDispatcher 对象注册事件侦听器对象,以使侦听器能够接收事件通知。
EventDispatcher
 Inherited
browse(typeFilter:Array = null):Boolean
显示一个文件浏览对话框,让用户选择要上载的文件。
FileReference
  
显示一个目录选择器对话框,用户可从中选择一个目录。
File
  
    browseForOpen(title:String, typeFilter:Array = null):void
显示“打开文件”对话框,用户可从中选择要打开的文件。
File
  
    browseForOpenMultiple(title:String, typeFilter:Array = null):void
显示“打开文件”对话框,用户可从中选择一个或多个要打开的文件。
File
  
    browseForSave(title:String):void
显示“保存文件”对话框,用户可从中选择一个文件目标。
File
  
    cancel():void
[覆盖] 取消任何未处理的异步操作。
File
  
    canonicalize():void
规范化 File 路径。
File
  
    clone():File
返回此 File 对象的副本。
File
  
    copyTo(newLocation:FileReference, overwrite:Boolean = false):void
将由此 File 对象指定的位置的文件或目录复制到由 newLocation 参数指定的位置。
File
  
    copyToAsync(newLocation:FileReference, overwrite:Boolean = false):void
开始将此 File 对象指定的位置中的文件或目录复制到 destination 参数指定的位置。
File
  
创建指定的目录和任何所需的父级目录。
File
  
[静态] 返回对新临时目录的引用。
File
  
[静态] 返回对新临时文件的引用。
File
  
    deleteDirectory(deleteDirectoryContents:Boolean = false):void
删除目录。
File
  
    deleteDirectoryAsync(deleteDirectoryContents:Boolean = false):void
异步删除目录。
File
  
    deleteFile():void
删除文件。
File
  
异步删除文件。
File
 Inherited
将事件调度到事件流中。
EventDispatcher
 Inherited
download(request:URLRequest, defaultFileName:String = null):void
打开对话框,以允许用户从远程服务器下载文件。
FileReference
  
返回与此 File 对象表示的目录中的文件和目录对应的 File 对象的数组。
File
  
异步检索与此 File 对象表示的目录内容对应的 File 对象的数组。
File
  
    getRelativePath(ref:FileReference, useDotDot:Boolean = false):String
查找两个 File 路径之间的相对路径。
File
  
[静态] 返回 File 对象的数组,列出文件系统根目录。
File
 Inherited
检查 EventDispatcher 对象是否为特定事件类型注册了任何侦听器。
EventDispatcher
 Inherited
表示对象是否已经定义了指定的属性。
Object
 Inherited
表示 Object 类的实例是否在指定为参数的对象的原型链中。
Object
 Inherited
开始加载用户选择的本地文件。
FileReference
  
    moveTo(newLocation:FileReference, overwrite:Boolean = false):void
将此 File 对象指定的位置中的文件或目录移动到 destination 参数指定的位置。
File
  
    moveToAsync(newLocation:FileReference, overwrite:Boolean = false):void
开始将此 File 对象指定的位置中的文件或目录移动到 newLocation 参数指定的位置。
File
  
    moveToTrash():void
将文件或目录移动到垃圾桶。
File
  
将文件或目录异步移动到垃圾桶。
File
  
打开操作系统注册的应用程序中的文件来打开此类型的文件。
File
 Inherited
表示指定的属性是否存在、是否可枚举。
Object
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
从 EventDispatcher 对象中删除侦听器。
EventDispatcher
  
[覆盖] 申请文件系统访问权限
File
  
    resolvePath(path:String):File
基于 path 参数(一个字符串)创建一个其路径相对于此 File 对象路径的新 File 对象。
File
 Inherited
save(data:*, defaultFileName:String = null):void
打开一个对话框,允许用户将文件保存到本地文件系统。
FileReference
 Inherited
设置循环操作动态属性的可用性。
Object
 Inherited
返回此对象的字符串表示形式,其格式设置遵守区域设置特定的约定。
Object
 Inherited
返回指定对象的字符串表示形式。
Object
 Inherited
upload(request:URLRequest, uploadDataFieldName:String = "Filedata", testUpload:Boolean = false):void
开始将文件上载到远程服务器。
FileReference
 Inherited
启动将文件上载到 URL 的操作,不进行任何编码。
FileReference
 Inherited
返回指定对象的原始值。
Object
 Inherited
检查是否用此 EventDispatcher 对象或其任何祖代为指定事件类型注册了事件侦听器。
EventDispatcher
事件
 事件 摘要 由以下参数定义
 Inherited[广播事件] Flash Player 或 AIR 应用程序获得操作系统焦点并变为活动状态时将调度此事件。EventDispatcher
  
    cancel
在取消未处理的异步操作时调度。File
  
    complete
在异步操作完成时调度。File
 Inherited[广播事件] Flash Player 或 AIR 应用程序失去操作系统焦点并变为非活动状态时将调度此事件。EventDispatcher
  当由于调用 getDirectoryListingAsync() 方法而提供目录列表时调度。File
 Inherited在 upload() 或 uploadUnencoded() 方法调用尝试通过 HTTP 访问数据,并且 Adobe AIR 可以检测并返回请求的状态代码时调度。FileReference
 Inherited当上载失败并且存在可用来描述失败的 HTTP 状态代码时调度。FileReference
  
    ioError
在执行异步文件操作期间发生错误时调度。File
 Inherited当上载或下载操作开始时调度。FileReference
  当应用程序申请文件系统访问权限时调度。File
 Inherited在文件上载或下载操作期间定期调度。FileReference
  当操作违反安全限制时调度。File
  
    select
当用户从文件浏览或目录浏览对话框中选择文件或目录时调度。File
  当用户从通过调用 browseForOpenMultiple() 方法打开的对话框中选择文件时调度。File
 Inherited成功上载并从服务器接收数据之后调度。FileReference
属性详细信息
    

applicationDirectory

属性
applicationDirectory:File  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

包含应用程序已安装文件的文件夹。

此对象的 url 属性使用 app URL 架构(而不是 file URL 架构)。这意味着指定的 url"app:"开头(而不是以 "file:" 开头)。此外,如果创建一个相对于 File.applicationDirectory 目录的 File 对象(通过使用 resolvePath() 方法),则该 File 对象的 url 也使用 app URL 架构。

注意:您无法写入其路径使用 app: URL 方案的文件或目录。您也无法删除或创建其路径使用 app: URL 方案的文件或文件夹。出于安全原因,不推荐修改应用程序目录中的内容,有些平台上的操作系统会阻止此操作。如果要存储特定于应用程序的数据,请考虑使用应用程序存储目录 (File.applicationStorageDirectory)。如果希望应用程序存储目录中的任何内容能够访问应用程序特许功能 (AIR API),您可以通过使用沙箱桥公开该功能。

applicationDirectory 属性可用于引用应用程序目录,它在所有平台上均有效。如果使用 nativePathurl 属性设置 File 对象,使其引用应用程序目录,此命令将仅在能够识别此路径的平台上有效。

在 Android 上,指向应用程序目录的 File 对象的 nativePath 属性是空字符串。使用 URL 属性访问应用程序文件。



实现
    public static function get applicationDirectory():File

相关 API 元素

    

applicationStorageDirectory

属性 
applicationStorageDirectory:File  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

应用程序的专用存储目录。

每个 AIR 应用程序都有一个唯一的、永久的应用程序存储目录,该目录是您首次访问 File.applicationStorageDirectory 时创建的。此目录对每个应用程序和用户是唯一的。此目录是存储特定于用户或特定于应用程序的数据的方便位置。

卸载 AIR 应用程序时,卸载程序是否删除应用程序存储目录及其文件取决于平台。

此对象的 url 属性使用 app-storage URL 架构(而不是 file URL 架构)。这意味着指定的 url 字符串以"app-storage:"开头(而不是以 "file:" 开头)。此外,如果创建一个相对于 File.applicationStoreDirectory 目录的 File 对象(通过使用 resolvePath() 方法),则该 File 对象的 url 也使用 app-storage URL 架构(如示例中所示)。

applicationStorageDirectory 属性可用于引用应用程序存储目录,它在所有平台上均有效。如果使用 nativePathurl 属性设置 File 对象,使其引用应用程序存储目录,此命令将仅在能够识别此路径的平台上有效。

注意(仅限 Mac OS): 为了符合 Mac App Store 的要求,此目录的物理位置在 AIR 3.2 和 AIR 3.3 之间发生了变化:

  • 3.2 命名空间和更早版本: ~/Library/Preferences/appid/Local Store/
  • 3.3 命名空间和更高版本: path/Library/Application Support/appid/Local Store/,其中 path 是 ~/Library/Containers/bundle-id/Data(沙箱环境)或 ~(当在沙箱环境外运行时)



实现
    public static function get applicationStorageDirectory():File

示例  ( 如何使用本示例 )
下面的代码创建一个 File 对象,该对象指向应用程序存储目录中的“images”子目录。
import flash.filesystem.File;

var tempFiles:File = File.applicationStorageDirectory;
tempFiles = tempFiles.resolvePath("images/");
trace(tempFiles.url); // app-storage:/images
    

cacheDirectory

属性 
cacheDirectory:File  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 3.6

应用程序的缓存目录。

cacheDirectory 属性提供一种引用缓存目录的方式。您的应用程序应使用缓存目录来存储从服务器下载的文件或可以重新生成的文件。例如,应放在缓存目录中的文件包括数据库缓存文件以及杂志、报纸及地图应用程序使用的可下载内容。

如果使用 nativePathurl 属性设置 File 对象来引用缓存目录,该对象将仅在能够识别此路径的平台上有效。

如果操作系统不支持缓存目录,则 cacheDirectory 为 null



实现
    public static function get cacheDirectory():File
    

desktopDirectory

属性 
desktopDirectory:File  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

用户桌面目录。

desktopDirectory 属性可用于引用桌面目录,它在所有平台上均有效。如果使用 nativePathurl 属性设置 File 对象,使其引用桌面目录,此命令将仅在能够识别此路径的平台上有效。

如果操作系统不支持桌面目录,则使用文件系统中适当的目录。

AIR for TV 设备没有用户桌面目录的概念。因此,desktopDirectory 属性引用与 File.userDirectory 属性相同的目录位置。用户目录对于应用程序而言是唯一的。



实现
    public static function get desktopDirectory():File

示例  ( 如何使用本示例 )
下面的代码输出用户桌面目录中包含的文件和目录的列表。
import flash.filesystem.File;
var desktop:File = File.desktopDirectory;

var files:Array = desktop.getDirectoryListing();

for (var i:uint = 0; i < files.length; i++) {
    trace(files[i].nativePath);
}
    

documentsDirectory

属性 
documentsDirectory:File  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

用户文档目录。

在 Windows 中,这是“My Documents”目录(例如,C:\Documents and Settings\userName\My Documents)。在 Mac OS 中,默认位置是 /Users/userName/Documents。在 Linux 中,默认位置是 /home/userName/Documents(英语系统上),并且该属性遵守 xdg-user-dirs 设置。

documentsDirectory 属性可用于引用文档目录,它在所有平台上均有效。如果使用 nativePathurl 属性设置 File 对象,使其引用文档目录,此命令将仅在能够识别此路径的平台上有效。

如果操作系统不支持文档目录,则使用文件系统中适当的目录。

AIR for TV 设备没有用户文档目录的概念。因此,documentsDirectory 属性引用与 File.userDirectory 属性相同的目录位置。用户目录对于应用程序而言是唯一的。



实现
    public static function get documentsDirectory():File

示例  ( 如何使用本示例 )
下面的代码使用 File.documentsDirectory 属性和 File.createDirectory() 方法来确保用户文档目录中存在一个名为“AIR Test”的目录。
import flash.filesystem.File;

var directory:File = File.documentsDirectory;
directory = directory.resolvePath("AIR Test");

File.createDirectory(directory);
trace(directory.exists); // true
    

downloaded

属性 
downloaded:Boolean

语言版本: ActionScript 3.0
运行时版本: AIR 2

表示是否已(从 Internet)下载参考文件或目录。

此属性仅在文件可以标记为已下载的操作系统上有意义:

  • Windows XP Service Pack 2 和更高版本,在 Windows Vista 上
  • Mac OS 10.5 和更高版本

在 Linux 等不标记已下载文件的系统上,此属性没有意义(其值设置为 false)。



实现
    public function get downloaded():Boolean
    public function set downloaded(value:Boolean):void

相关 API 元素

    

exists

属性 
exists:Boolean  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

表示引用的文件或目录是否存在。如果 File 对象指向现有的文件或目录,则该值为 true;否则为 false



实现
    public function get exists():Boolean

示例  ( 如何使用本示例 )
下面的代码创建一个临时文件,然后将其删除,并使用 File.exists 属性来检查该文件是否存在。
import flash.filesystem.*;

var temp:File = File.createTempFile();
trace(temp.exists); // true
temp.deleteFile();
trace(temp.exists); // false
    

icon

属性 
icon:Icon  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

包含为文件定义的图标的 Icon 对象。Icon 对象是与各种图标状态相对应的 BitmapData 对象的数组。在 Linux 中,Icon 对象不包含图标。在 Android 上,icon 属性为 null



实现
    public function get icon():Icon

示例  ( 如何使用本示例 )
下面的代码显示如何在 icon 数组中查找具有最大高度的图像,并将该图像设置为 Bitmap 对象。
import flash.filesystem.File;
import flash.display.*;

var directory:File = File.documentsDirectory;
var bitmaps:Array = directory.icon.bitmaps;
var bmpData:BitmapData = new BitmapData(1, 1);
for (var i:uint = 0; i < bitmaps.length; i++) {
    if (bitmaps[i].height > bmpData.height) {
        bmpData = directory.icon.bitmaps[i];
    }
}
var iconBmp:Bitmap = new Bitmap(bmpData);
您可以将此 Bitmap 对象作为显示对象容器的子项(如 Sprite 对象或 Flex UIComponent 对象)进行添加。
    

isDirectory

属性 
isDirectory:Boolean  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

表示是否为对目录的引用。如果 File 对象指向一个目录,则该值为 true;否则为 false



实现
    public function get isDirectory():Boolean

示例  ( 如何使用本示例 )
下面的代码创建指向用户目录中文件和目录的 File 对象的数组,然后使用 isDirectory 属性仅列出指向目录(而不是文件)的那些 File 对象。
import flash.filesystem.*;

var userDirFiles:Array = File.userDirectory.getDirectoryListing();
for (var i:uint = 0; i < userDirFiles.length; i++) {
    if (userDirFiles[i].isDirectory) {
        trace(userDirFiles[i].nativePath);
    }
}    
    

isHidden

属性 
isHidden:Boolean  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

表示引用的文件或目录是否为“隐藏”。如果引用的文件或目录是隐藏的,则该值为 true;否则为 false



实现
    public function get isHidden():Boolean

示例  ( 如何使用本示例 )
下面的代码创建指向用户目录中文件和目录的 File 对象的数组,然后使用 isHidden 属性列出隐藏的文件和目录。
import flash.filesystem.*;

var userDirFiles:Array = File.userDirectory.getDirectoryListing();
for (var i:uint = 0; i < userDirFiles.length; i++) {
    if (userDirFiles[i].isHidden) {
        trace(userDirFiles[i].nativePath);
    }
}    
    

isPackage

属性 
isPackage:Boolean  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

表示引用的目录是否为包。

如果引用的目录是包,则该值为 true;否则为 false。请注意,File 类不允许直接创建包。

  • 在 Mac OS 中,目录可以指定为包并将作为单个文件而不是目录显示在 Finder 中。如果引用的目录是包,则将此属性设置为 true;如果该文件不是目录、不存在或不是包,则将此属性设置为 false
  • 在其他操作系统上,此属性始终设置为 false



实现
    public function get isPackage():Boolean
    

isSymbolicLink

属性 
isSymbolicLink:Boolean  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

表示引用是否为符号链接。

如果 File 对象是一个符号链接,则该值为 true;否则为 false。请注意,File 类不允许直接创建符号链接。

符号链接允许一个文件指向磁盘上的另一个文件或目录。符号链接虽然与 Mac OS 中的别名和 Windows 中的快捷方式相似,但并不相同。别名或快捷方式始终报告为文件(而不是目录),读取或写入别名或快捷方式从不影响它指向的原始文件或目录。另一方面,符号链接的行为大体上与其所指向的文件或目录类似。它可以报告为文件或目录,读取或写入符号链接将会影响它指向的文件或目录,而不影响符号链接本身。删除符号链接,但删除的是链接,而非链接的目标。

Mac ® OS ®、Linux 和 Windows ® Vista ® 支持符号链接。此外,在 Windows 中,引用交接点(用于 NTFS 文件系统)的 File 对象的 isSymbolicLink 属性设置为 true



实现
    public function get isSymbolicLink():Boolean
    

lineEnding

属性 
lineEnding:String  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

主机操作系统使用的行结束字符序列。

在 Mac OS 和 Linux 中,这是换行符(十六进制字符代码 0x0A)。在 Windows 中,它是回车符(十六进制字符代码 0x0D),后跟换行符(十六进制字符代码 0x0A)。



实现
    public static function get lineEnding():String

示例  ( 如何使用本示例 )
下面的代码将一个字符串 (str) 写入文本文件,并使用 File.lineEnding 静态属性,用主机操作系统首选的行尾符来替换换行符的所有实例(在代码中用正则表达式 /\n/g 表示)。
import flash.filesystem.*;

var str:String = "Hello\n" + 
        "World\n";
str = str.replace(/\n/g, File.lineEnding);
var file:File = File.documentsDirectory.resolvePath("AIR Test/test.txt");
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.WRITE);
fileStream.writeUTF(str);
fileStream.close();
    

nativePath

属性 
nativePath:String

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

采用主机操作系统表示形式的完整路径。在 Mac OS 和 Linux 中,使用正斜杠 (/) 字符作为路径分隔符。但在 Windows 中,可以使用正斜杠字符或反斜杠 (\) 字符作为路径分隔符来设置 nativePath 属性,AIR 会自动用相应的反斜杠字符来替换正斜杠。

在使用 set 命令,以代码形式直接设置 nativePath 属性之前,请考虑这是否会生成平台专用代码。例如,“C:\\Documents and Settings\\bob\\Desktop”这样的本机路径仅在 Windows 上有效。较好的方法是使用以下这些静态属性,它们可以表示常用目录,且在所有平台上均有效:

  • File.applicationDirectory
  • File.applicationStorageDirectory
  • File.desktopDirectory
  • File.documentsDirectory
  • File.userDirectory

可以使用 resolvePath() 方法获取这些目录的相对路径。

某些 Flex API(如 SWFLoader 类的 source 属性)使用 URL(File 对象的 url 属性),而不使用本机路径(nativePath 属性)。



实现
    public function get nativePath():String
    public function set nativePath(value:String):void

引发
ArgumentError — 路径的语法无效。
 
SecurityError — 调用方不在应用程序安全沙箱中。

示例  ( 如何使用本示例 )
下面的代码显示 File 对象的 nativePath 属性和 url 属性之间的区别。注释将在示例 Windows 计算机上显示结果。
import flash.filesystem.File;

var docs:File = File.documentsDirectory;
trace(docs.nativePath); // C:\Documents and Settings\turing\My Documents
trace(docs.url); // file:///C:/Documents%20and%20Settings/turing/My%20Documents
    

parent

属性 
parent:File  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

包含此 File 对象引用的文件或目录的目录。

如果文件或目录不存在,则 parent 属性仍然返回指向包含目录的 File 对象(即使该目录不存在)。

此属性与 resolvePath("..") 的返回值相同,只不过根目录的父级为 null



实现
    public function get parent():File

示例  ( 如何使用本示例 )
下面的代码使用 parent 属性显示包含临时文件的目录。
import flash.filesystem.File;

var tempFile:File = File.createTempDirectory();
trace(tempFile.parent.nativePath);
tempFile.deleteFile();
    

permissionStatus

属性 
permissionStatus:String  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 24.0

确定应用程序是否已被授予文件系统访问权限。



实现
    public static function get permissionStatus():String

相关 API 元素

    

preventBackup

属性 
preventBackup:Boolean

语言版本: ActionScript 3.0
运行时版本: AIR 3.6

指示运行时是否阻止此 File 对象备份到云。

如果此属性设为 true,则在提供云服务的平台上,不会自动将其备份到云。此属性的默认值是 false。



实现
    public function get preventBackup():Boolean
    public function set preventBackup(value:Boolean):void
    

separator

属性 
separator:String  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

主机操作系统的路径组件分隔符。

在 Mac OS 和 Linux 中,这是正斜杠 (/) 字符。在 Windows 中,它是反斜杠 (\) 字符。

注意:当在字符串中使用反斜杠时,请记住键入该字符两次(例如“directory\\file.ext”)。字符串中的每一对反斜杠在字符串中均表示单个反斜杠。



实现
    public static function get separator():String

示例  ( 如何使用本示例 )
下面的代码使用 getRelativePath() 方法获取目录和文件之间的相对路径。然后,代码使用 File.separator 静态属性,用操作系统所用的分隔符来替换路径中的正斜杠 (/) 字符,在 Windows 中为反斜杠 (\),在其他操作系统中为正斜杠。
import flash.filesystem.File;

var directory:File = File.documentsDirectory.resolvePath("Apollo Test");
var file:File = File.documentsDirectory.resolvePath("Apollo Test/employees/bob/test.txt");

var relativePath:String = directory.getRelativePath(file); // employees/bob/test.txt
relativePath = relativePath.replace(/\//g, File.separator);
trace(relativePath); 
在此示例中,replace() 方法使用正则表达式 /\//g所有 正斜杠字符匹配。
    

spaceAvailable

属性 
spaceAvailable:Number  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 1.1

可用于在此 File 位置使用的空间,以字节为单位。

如果 File 对象引用一个目录,则 spaceAvailable 将表示可供文件使用的目录空间。如果 File 对象引用一个文件,则 spaceAvailable 将表示可供该文件使用的空间。如果该文件位置不存在,则 spaceAvailable 将设置为 0。如果 File 对象引用一个符号链接,则 spaceAvailable 将表示符号链接指向的位置的可用空间。

通常,目录或文件的可用空间与包含目录或文件的卷上的可用空间相同。不过,可用空间与磁盘配额及每个目录的空间限制有关。

将文件或目录添加到卷中通常需要比文件的实际大小或目录中内容的实际大小更多的空间。例如,操作系统可能需要更多空间来存储索引信息。或者,所需的磁盘扇区可能会使用额外的空间。此外,可用空间是动态变化的。因此,您不能期望为文件存储分配报告的全部 空间。



实现
    public function get spaceAvailable():Number
    

systemCharset

属性 
systemCharset:String  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

主机操作系统使用的默认编码。

可能值包括“windows-1252”“shift-jis”“cn-gb”“iso-8859-1”等。有关完整列表,请参阅支持的字符集

在使用 FileStream 类的 readMultiByte()writeMultiByte() 方法时,可以使用此值。



实现
    public static function get systemCharset():String

相关 API 元素


示例  ( 如何使用本示例 )
下面的代码打开一个文件(用户文档目录的 AIR Test 子目录中的 test.txt 文件),并使用 File.systemCharset 静态属性作为 FileStream 对象的 readMultiByte() 方法调用的 charSet 参数。
import flash.filesystem.File;

var file:File = File.documentsDirectory.resolvePath("AIR Test/test.txt");
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.READ);
var str:String = fileStream.readMultiByte(file.size, File.systemCharset);
trace(str);    
    

url

属性 
url:String

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

此文件路径的 URL。

如果这是对应用程序存储目录中的路径的引用,则 URL 架构为 "app-storage";如果这是对应用程序目录中路径的引用,则 URL 架构为 "app";否则此架构为 "file"

在向 url 属性值时,可以使用空格字符(而不是 "%20");AIR 会自动对该字符串进行编码(例如,将空格转换为 "%20")。



实现
    public function get url():String
    public function set url(value:String):void

引发
ArgumentError — URL 语法无效。
 
SecurityError — 调用方不在应用程序安全沙箱中。

相关 API 元素


示例  ( 如何使用本示例 )
下面的代码显示 File 对象的 nativePath 属性和 url 属性之间的区别。注释将在示例 Windows 计算机上显示结果。
import flash.filesystem.File;

var docs:File = File.documentsDirectory;
trace(docs.nativePath); // C:\Documents and Settings\turing\My Documents
trace(docs.url); // file:///C:/Documents%20and%20Settings/turing/My%20Documents
    

userDirectory

属性 
userDirectory:File  [只读]

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

用户目录。

在 Windows 中,这是“My Documents”目录的父级(例如,C:\Documents and Settings\userName)。在 Mac OS 中,它是 /Users/userName. 在 Linux 中,它是 /home/userName。

userDirectory 属性可用于引用用户目录,它在所有平台上均有效。如果直接设置 File 对象的 nativePathurl 属性,此命令将仅在能够识别此路径的平台上有效。

如果操作系统不支持用户目录,则使用文件系统中适当的目录。

在 AIR for TV 设备上,userDirectory 属性引用对于应用程序是唯一的用户目录。



实现
    public static function get userDirectory():File

示例  ( 如何使用本示例 )
下面的代码输出用户目录的根级别包含的文件和目录的列表:
import flash.filesystem.File;

var files:Array = File.userDirectory.listDirectory();
for (var i:uint = 0; i < files.length; i++) {
    trace(files[i].nativePath);
}
构造函数详细信息
    

File

()构造函数
public function File(path:String = null)

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

File 类的构造函数。

如果传递 path 参数,File 对象将指向指定的路径,并将设置 nativePath 属性和 url 属性以反映该路径。

尽管可以传递 path 参数来指定文件路径,但请考虑这是否会生成平台专用代码。例如,这样的本机路径 "C:\\Documents and Settings\\bob\\Desktop",或这样的 URL "file:///C:/Documents%20and%20Settings/bob/Desktop" 仅在 Windows 上有效。较好的方法是使用以下这些静态属性,它们可以表示常用目录,且在所有平台上均有效:

  • File.applicationDirectory
  • File.applicationStorageDirectory
  • File.desktopDirectory
  • File.documentsDirectory
  • File.userDirectory

然后可以使用 resolvePath() 方法来获取这些目录的相对路径。例如,以下代码可以设置 File 对象,使其指向应用程序存储目录中的 settings.xml 文件:

var file:File = File.applicationStorageDirectory.resolvePath("settings.xml");

重要:如果在 path 参数中传递 URL 字符串,将解码 URL 以解析文件路径。例如,语句 new File("file:///c:/test/demo%20file%201%2e0.txt") 使用本机路径“c:\test\demo file 1.0.txt”创建一个 File 对象。(使用 file:、app: 或 app-storage: 方案前缀的 URL。)然而,如果省略了有效的 URL 前缀,则路径字符串将被作为本机路径处理,不会发生解码操作。在验证来自可能不受信任的源的路径时,必须考虑这种行为。如果仅验证输入字符串,URL 解码操作可能会让攻击者绕过您的验证检查。请始终验证实例化 File 对象的最终路径:

     var file:File = new File( taintedString );
     validate( file.nativePath ); //where validate() is your path validation function
     

参数
path:String (default = null) — 文件的路径。可以通过使用 URL 或使用本机路径(特定于平台)表示法来指定路径。

如果指定 URL,则可以使用以下 URL 架构之一:fileappapp-storage。下面是使用 URL 表示法时 path 参数的有效值:

  • “app:/DesktopPathTest.xml”
  • “app-storage:/preferences.xml”
  • “file:///C:/Documents%20and%20Settings/bob/Desktop”(Bob 的 Windows 计算机桌面)
  • “file:///Users/bob/Desktop”(Bob 的 Mac 计算机桌面)

appapp-storage URL 方案很有用,因为这些方案在所有文件系统中均可指向有效的文件。不过,在另外两个使用 file URL 架构指向用户桌面目录的示例中,最好是path 参数传递给 File() 构造函数,然后将 File.desktopDirectory 分配给 File 对象,以此作为访问独立于平台和独立于用户的桌面目录的方式。

如果指定本机路径,则在 Windows 中可以使用反斜杠字符或正斜杠字符作为此参数中的路径分隔符;在 Mac OS 和 Linux 中则使用正斜杠字符。下面是使用本机路径表示法时 path 参数的有效值:

  • “C:/Documents and Settings/bob/Desktop”
  • “/Users/bob/Desktop”

不过,对于这两个示例,不应path 参数传递给 File() 构造函数,然后将 File.desktopDirectory 分配给 File 对象,以此作为访问独立于平台和独立于用户的桌面目录的方式。


引发
ArgumentError path 参数的语法无效。

相关 API 元素

方法详细信息

    browseForDirectory

()方法
public function browseForDirectory(title:String):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

显示一个目录选择器对话框,用户可从中选择一个目录。当用户选择该目录时,将调度 select 事件。select 事件的 target 属性是指向所选目录的 File 对象。

目录选择器对话框并不始终显示在由另一个窗口(具有非空 owner 属性的窗口)拥有的窗口的前面。 要避免窗口顺序问题,请在调用此方法之前隐藏所拥有的窗口。

注意:在 Android 设备上,不支持 browseForDirectory()。File 对象立即调度 cancel 事件。

参数

title:String — 显示在对话框标题栏中的字符串。


事件
cancel:Event — 在用户单击“打开文件”对话框中的“取消”按钮时调度。
 
select:Event — 在用户选择目录并关闭目录选择器对话框时调度。
 
ioError:IOErrorEvent — 在此平台上不支持浏览操作。

引发
IllegalOperationError — 当前正在运行浏览操作(browseForOpen()、browseForOpenMultiple()、browseForSave()、browseForDirectory())。
 
SecurityError — 应用程序没有必要权限。

相关 API 元素


示例  ( 如何使用本示例 )

下面的代码使用 File.browseForDirectory() 方法让用户选择一个目录。当选择目录时,此代码会在 trace() 输出中列出所选目录的内容。
import flash.filesystem.File;
import flash.events.Event;

var directory:File = File.documentsDirectory;

try
{
    directory.browseForDirectory("Select Directory");
    directory.addEventListener(Event.SELECT, directorySelected);
}
catch (error:Error)
{
    trace("Failed:", error.message);
}

function directorySelected(event:Event):void 
{
    directory = event.target as File;
    var files:Array = directory.getDirectoryListing();
    for(var i:uint = 0; i < files.length; i++)
    {
        trace(files[i].name);
    }
}

    browseForOpen

()方法 
public function browseForOpen(title:String, typeFilter:Array = null):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

显示“打开文件”对话框,用户可从中选择要打开的文件。

当用户选择该文件时,将调度 select 事件。select 事件的 target 属性是指向所选文件的 File 对象。

“打开文件”对话框并不始终显示在由另一个窗口(具有非空 owner 属性的窗口)拥有的窗口的前面。 要避免窗口顺序问题,请在调用此方法之前隐藏所拥有的窗口。

注意:在 Android 设备上,无法设置文件对话框标题。忽略 title 参数。

参数

title:String — 显示在对话框标题栏中的字符串。
 
typeFilter:Array (default = null) — 一个 FileFilter 实例数组,用于过滤在对话框中显示的文件。如果省略此参数,则显示所有文件。有关详细信息,请参阅 FileFilter 类。


事件
cancel:Event — 在用户单击“打开文件”对话框中的“取消”按钮时调度。
 
select:Event — 在用户选择文件并关闭“打开文件”对话框时调度。
 
ioError:IOErrorEvent — 在此平台上不支持浏览操作。

引发
IllegalOperationError — 当前正在运行浏览操作(browseForOpen()、browseForOpenMultiple()、browseForSave()、browseForDirectory())。
 
SecurityError — 应用程序没有必要权限。

相关 API 元素


示例  ( 如何使用本示例 )

下面的代码使用 File.browseForOpen() 方法让用户选择一个文本文件。当选择此文件时,此代码将文件数据读入到字符串中。
import flash.filesystem.*;
import flash.events.Event;
import flash.net.FileFilter;

var fileToOpen:File = new File();
var txtFilter:FileFilter = new FileFilter("Text", "*.as;*.css;*.html;*.txt;*.xml");

try 
{
    fileToOpen.browseForOpen("Open", [txtFilter]);
    fileToOpen.addEventListener(Event.SELECT, fileSelected);
}
catch (error:Error)
{
    trace("Failed:", error.message);
}

function fileSelected(event:Event):void 
{
    var stream:FileStream = new FileStream();
    stream.open(event.target, FileMode.READ);
    var fileData:String = stream.readUTFBytes(stream.bytesAvailable);
    trace(fileData);
}

    browseForOpenMultiple

()方法 
public function browseForOpenMultiple(title:String, typeFilter:Array = null):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

显示“打开文件”对话框,用户可从中选择一个或多个要打开的文件。

当用户选择文件时,将调度 selectMultiple 事件。select 事件的 target 属性是此 File 对象。与 browseForOpen() 不同,使用 browseForOpenMultiple() 方法时,此 File 对象不会更新以引用任何所选的文件。相反,生成的 selectMultiple 事件包含所选文件的数组。

“打开文件”对话框并不始终显示在由另一个窗口(具有非空 owner 属性的窗口)拥有的窗口的前面。 要避免窗口顺序问题,请在调用此方法之前隐藏所拥有的窗口。

注意:在 Android 设备上,无法设置文件对话框标题。忽略 title 参数。

参数

title:String — 显示在对话框标题栏中的字符串。
 
typeFilter:Array (default = null) — 一个 FileFilter 实例数组,用于过滤在对话框中显示的文件。如果省略此参数,则显示所有文件。有关详细信息,请参阅 FileFilter 类。


事件
cancel:Event — 在用户单击“打开文件”对话框中的“取消”按钮时调度。
 
selectMultiple:FileListEvent — 在用户选择文件并关闭“打开文件”对话框时调度。
 
ioError:IOErrorEvent — 在此平台上不支持浏览操作。

引发
IllegalOperationError — 当前正在运行浏览操作(browseForOpen()、browseForOpenMultiple()、browseForSave()、browseForDirectory())。
 
SecurityError — 应用程序没有必要权限。

相关 API 元素


示例  ( 如何使用本示例 )

下面的代码使用 File.browseForOpenMultiple() 方法让用户选择多个文件。当选择多个文件时,此代码输出所选文件的路径。
import flash.filesystem.*;
import flash.events.FileListEvent;

var docsDir:File = File.documentsDirectory;
try
{
    docsDir.browseForOpenMultiple("Select Files");
    docsDir.addEventListener(FileListEvent.SELECT_MULTIPLE, filesSelected);
}
catch (error:Error)
{
    trace("Failed:", error.message);
}

function filesSelected(event:FileListEvent):void 
{
    for (var i:uint = 0; i < event.files.length; i++) 
    {
        trace(event.files[i].nativePath);
    }
}

    browseForSave

()方法 
public function browseForSave(title:String):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

显示“保存文件”对话框,用户可从中选择一个文件目标。

当用户选择该文件时,将调度 select 事件。select 事件的 target 属性是指向所选保存目标的 File 对象。

“保存文件”对话框并不始终显示在由另一个窗口(具有非空 owner 属性的窗口)拥有的窗口的前面。 要避免窗口顺序问题,请在调用此方法之前隐藏所拥有的窗口。

注意:在 Android 设备上,无法设置文件对话框标题。忽略 title 参数。

参数

title:String — 显示在对话框标题栏中的字符串。


事件
cancel:Event — 在用户单击“保存文件”对话框中的“取消”按钮时调度。
 
select:Event — 在用户选择文件并关闭“保存文件”对话框时调度。
 
ioError:IOErrorEvent — 在此平台上不支持浏览操作。

引发
IllegalOperationError — 当前正在运行浏览操作(browseForOpen()、browseForOpenMultiple()、browseForSave()、browseForDirectory())。
 
SecurityError — 应用程序没有必要权限。

相关 API 元素


示例  ( 如何使用本示例 )

下面的代码使用 File.browseForSave() 方法让用户选择用于保存文件的路径。在选择文件时,此代码将数据保存到所选的文件路径。
import flash.filesystem.*;
import flash.events.Event;

var docsDir:File = File.documentsDirectory;
try
{
    docsDir.browseForSave("Save As");
    docsDir.addEventListener(Event.SELECT, saveData);
}
catch (error:Error)
{
    trace("Failed:", error.message);
}

function saveData(event:Event):void 
{
    var newFile:File = event.target as File;
    var str:String = "Hello.";
    if (!newFile.exists)
    {
        var stream:FileStream = new FileStream();
        stream.open(newFile, FileMode.WRITE);
        stream.writeUTFBytes(str);
        stream.close();
    }
}

    cancel

()方法 
override public function cancel():void

运行时版本: AIR 1.0

取消任何未处理的异步操作。

    canonicalize

()方法 
public function canonicalize():void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

规范化 File 路径。

如果 File 对象表示现有的文件或目录,规范化将调整该路径,使其与实际文件名或目录名的大小写相匹配。如果 File 对象是符号链接,规范化将调整该路径,使其与该链接所指向的文件或目录相匹配,不管所指向的文件或目录是否存在。在区分大小写的文件系统(如 Linux)上,当多个文件的名称只有大小写不同时,canonicalize() 方法将调整路径以匹配最先找到的文件(以文件系统确定的顺序)。

此外,在 Windows 中,规范化会将短文件名转换成长文件名。


示例  ( 如何使用本示例 )

下面的代码显示如何使用 canonicalize() 方法查找目录名的正确大小写。运行此示例前,在您的计算机桌面上创建一个名为 AIR Test 的目录。
import flash.filesystem.*;

var path:File = File.desktopDirectory.resolvePath("air test");
trace(path.nativePath); 
path.canonicalize();
trace(path.nativePath); // ...\AIR Test


下面的代码显示如何使用 canonicalize() 方法基于 Windows 目录的短名称查找其长名称。此示例假定在 C: 驱动器的根目录中有一个 AIR Test 目录,并且系统已将短名称 AIR~1 分配给该目录。
import flash.filesystem.*;

var path:File = new File();
path.nativePath = "C:\\AIR~1";
path.canonicalize();
trace(path.nativePath); // C:\AIR Test

    clone

()方法 
public function clone():File

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

返回此 File 对象的副本。未复制事件注册。

注意:此方法 复制文件本身。它仅制作 ActionScript File 对象实例的副本。要复制文件,请使用 copyTo() 方法。

返回
File

    copyTo

()方法 
public function copyTo(newLocation:FileReference, overwrite:Boolean = false):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

将由此 File 对象指定的位置的文件或目录复制到由 newLocation 参数指定的位置。复制过程将创建任何需要的父级目录(如有可能)。当使用 copyto() 来覆盖文件时,文件的属性也将会被覆盖。

参数

newLocation:FileReference — 新文件的目标位置。请注意,此 File 对象指定生成(复制)的文件或目录,不是 包含该文件或目录的目录的路径。
 
overwrite:Boolean (default = false) — 如果为 false,则当由 target 参数指定的文件已经存在时复制将失败。如果为 true,该操作将覆盖现有的同名文件或目录。


引发
IOError — 源不存在;或者目标存在且 overwritefalse;或者无法将源复制到目标;或者源和目标引用相同的文件或文件夹且 overwrite 设置为 true。在 Windows 中无法复制打开的文件,也无法复制包含已打开文件的目录。
 
SecurityError — 应用程序没有向目标写入的必要权限。

相关 API 元素


示例  ( 如何使用本示例 )

下面的代码显示如何使用 copyTo() 方法复制文件。运行此代码之前,请在计算机上文档目录的 AIR Test 子目录中创建一个 test1.txt 文件。生成的复制文件名为 test2.txt,并且也在 AIR Test 子目录中。将 overwrite 参数设置为 true 时,此操作将覆盖任何现有的 test2.txt 文件。
import flash.filesystem.File;
import flash.events.Event;

var sourceFile:FileReference = File.documentsDirectory;
sourceFile = sourceFile.resolvePath("AIR Test/test1.txt");
var destination:FileReference = File.documentsDirectory;
destination = destination.resolvePath("AIR Test/test2.txt");

if (sourceFile.copyTo(destination, true)) {
    trace("Done.");
}

下面的代码显示如何使用 copyTo() 方法复制文件。运行此代码之前,在计算机上主目录的 AIR Test 子目录中创建一个 test1.txt 文件。生成的复制文件名为 test2.txt。trycatch 语句显示如何响应错误。
import flash.filesystem.File;

var sourceFile:File = File.documentsDirectory;
sourceFile = sourceFile.resolvePath("AIR Test/test1.txt");
var destination:File = File.documentsDirectory;
destination = destination.resolvePath("AIR Test/test2.txt");

try 
{
    sourceFile.copyTo(destination, true);
}
catch (error:Error)
{
    trace("Error:", error.message);
}

    copyToAsync

()方法 
public function copyToAsync(newLocation:FileReference, overwrite:Boolean = false):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

开始将此 File 对象指定的位置中的文件或目录复制到 destination 参数指定的位置。

完成后,将调度 complete 事件(成功)或 ioError 事件(失败)。复制过程将创建任何需要的父级目录(如有可能)。

参数

newLocation:FileReference — 新文件的目标位置。请注意,此 File 对象指定生成(复制)的文件或目录,不是 包含该文件或目录的目录的路径。
 
overwrite:Boolean (default = false) — 如果为 false,则当由 target 文件指定的文件已经存在时复制将失败。如果为 true,则该操作将覆盖任何现有的同名文件或目录。


事件
complete:Event — 在文件或目录已成功复制时调度。
 
ioError:IOErrorEvent — 源不存在;或者目标存在且 overwritefalse;或者无法将源复制到目标;或者源和目标引用相同的文件或文件夹且 overwrite 设置为 true。在 Windows 中无法复制打开的文件,也无法复制包含已打开文件的目录。

引发
SecurityError — 应用程序没有向目标写入的必要权限。

相关 API 元素


示例  ( 如何使用本示例 )

下面的代码显示如何使用 copyToAsync() 方法复制文件。在运行此代码之前,请确保在计算机上文档目录的 AIR Test 子目录中创建一个 test1.txt 文件。生成的复制文件名为 test2.txt,并且也在 AIR Test 子目录中。将 overwrite 参数设置为 true 时,此操作将覆盖任何现有的 test2.txt 文件。
import flash.filesystem.File;
import flash.events.Event;

var sourceFile:File = File.documentsDirectory;
sourceFile = sourceFile.resolvePath("AIR Test/test1.txt");
var destination:File = File.documentsDirectory;
destination = destination.resolvePath("AIR Test/test2.txt");

sourceFile.copyToAsync(destination, true);
sourceFile.addEventListener(Event.COMPLETE, fileCopiedHandler);

function fileCopiedHandler(event:Event):void {
    trace("Done.");
}

    createDirectory

()方法 
public function createDirectory():void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

创建指定的目录和任何所需的父级目录。如果该目录已存在,则不执行任何操作。


引发
IOError — 目录不存在且无法创建。
 
SecurityError — 应用程序没有必要权限。

示例  ( 如何使用本示例 )

下面的代码将桌面上名为 test.txt 的文件移动到文档目录的 AIR Test 子目录中。调用 createDirectory() 方法以确保 AIR Test 目录存在后才移动此文件。
import flash.filesystem.*;

var source:File = File.desktopDirectory.resolvePath("test.txt");
var target:File = File.documentsDirectory.resolvePath("AIR Test/test.txt");
var targetParent:File = target.parent;
targetParent.createDirectory();
source.moveTo(target, true);

    createTempDirectory

()方法 
public static function createTempDirectory():File

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

返回对新临时目录的引用。这是一个位于系统临时目录路径中的新目录。

使用此方法来标识新的唯一目录,无需查询系统即可以确定该目录是新的唯一目录。

您可能需要在关闭应用程序前删除该临时目录,因为在某些设备上它不会自动删除。

返回
File — 引用新临时目录的 File 对象。

相关 API 元素


示例  ( 如何使用本示例 )

下面的代码使用 createTempFile() 方法获取对新临时目录的引用。
import flash.File;

var temp:File = File.createTempDirectory();
trace(temp.nativePath);
每次运行此代码时都会创建一个新的(唯一的)文件。

    createTempFile

()方法 
public static function createTempFile():File

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

返回对新临时文件的引用。这是一个位于系统临时目录路径中的新文件。

使用此方法来标识新的唯一文件,无需查询系统即可以确定该文件是新的唯一文件。

您可能需要在关闭应用程序前删除该临时文件,因为它不会自动删除。

返回
File — 引用新临时文件的 File 对象。

相关 API 元素


示例  ( 如何使用本示例 )

下面的代码使用 createTempFile() 方法获取对新临时文件的引用。
import flash.File;

var temp:File = File.createTempFile();
trace(temp.nativePath);
每次运行此代码时都会创建一个新的(唯一的)文件。

    deleteDirectory

()方法 
public function deleteDirectory(deleteDirectoryContents:Boolean = false):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

删除目录。如果此 File 实际上是指向目录的符号链接,则删除的是链接,而非目录。

参数

deleteDirectoryContents:Boolean (default = false) — 指定是否删除包含文件或子目录的目录。如果为 false,则当该目录包含文件或目录时,调用此方法将引发异常。


引发
IOError — 目录不存在或无法删除。在 Windows 中无法删除包含已打开文件的目录。
 
SecurityError — 应用程序没有删除目录的必要权限。

相关 API 元素


示例  ( 如何使用本示例 )

下面的代码创建一个空目录,然后使用 deleteDirectory() 方法删除该目录。
import flash.filesystem.File;

var directory:File = File.documentsDirectory.resolvePath("Empty Junk Directory/");
File.createDirectory(directory);
trace(directory.exists); // true
directory.deleteDirectory();
trace(directory.exists); // false

    deleteDirectoryAsync

()方法 
public function deleteDirectoryAsync(deleteDirectoryContents:Boolean = false):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

异步删除目录。如果此 File 实际上是指向目录的符号链接,则删除的是链接,而非目录。

参数

deleteDirectoryContents:Boolean (default = false) — 指定是否删除包含文件或子目录的目录。如果为 false,则当该目录包含文件或目录时,File 对象将调度 ioError 事件。


事件
complete:Event — 在目录已成功删除时调度。
 
ioError:IOErrorEvent — 目录不存在或无法删除。在 Windows 中无法删除包含已打开文件的目录。

引发
SecurityError — 应用程序没有删除目录的必要权限。

相关 API 元素

    deleteFile

()方法 
public function deleteFile():void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

删除文件。如果此 File 实际上是符号链接,则删除的是链接,而非目标文件。


引发
IOError — 文件不存在或无法删除。在 Windows 中无法删除当前打开的文件。
 
SecurityError — 应用程序没有删除文件的必要权限。

相关 API 元素


示例  ( 如何使用本示例 )

下面的代码创建一个临时文件,然后调用 deleteFile() 方法以删除该文件。
import flash.filesystem.*;

var file:File = File.createTempFile();
trace(file.exists); // true
file.deleteFile();
trace(file.exists); // false

    deleteFileAsync

()方法 
public function deleteFileAsync():void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

异步删除文件。如果此 File 实际上是符号链接,则删除的是链接,而非目标文件。


事件
complete:Event — 在文件已成功删除时调度。
 
ioError:IOErrorEvent — 文件不存在或无法删除。在 Windows 中无法删除当前打开的文件。

引发
SecurityError — 应用程序没有删除文件的必要权限。

相关 API 元素

    getDirectoryListing

()方法 
public function getDirectoryListing():Array

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

返回与此 File 对象表示的目录中的文件和目录对应的 File 对象的数组。此方法不浏览子目录的内容。

返回
Array — File 对象的数组。

相关 API 元素


示例  ( 如何使用本示例 )

下面的代码显示如何使用 getDirectoryListing() 方法枚举用户目录的内容。
import flash.filesystem.File;

var directory:File = File.userDirectory;
var list:Array = directory.getDirectoryListing();
for (var i:uint = 0; i < list.length; i++) {
    trace(list[i].nativePath);
}

    getDirectoryListingAsync

()方法 
public function getDirectoryListingAsync():void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

异步检索与此 File 对象表示的目录内容对应的 File 对象的数组。


事件
ioError:ErrorEvent — 您没有足够的权限读取此目录,或此目录不存在。
 
directoryListing:FileListEvent — 目录内容已成功枚举。contents 事件具有一个 files 属性,该属性是生成的 File 对象数组。

相关 API 元素


示例  ( 如何使用本示例 )

下面的代码显示如何使用 getDirectoryListingAsync() 方法枚举用户目录的内容。
import flash.filesystem.File;
import flash.events.FileListEvent;

var directory:File = File.userDirectory;
directory.getDirectoryListingAsync();
directory.addEventListener(FileListEvent.DIRECTORY_LISTING, directoryListingHandler);

function directoryListingHandler(event:FileListEvent):void {
    var list:Array = event.files;
    for (var i:uint = 0; i < list.length; i++) {
        trace(list[i].nativePath);
    }
}

    getRelativePath

()方法 
public function getRelativePath(ref:FileReference, useDotDot:Boolean = false):String

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

查找两个 File 路径之间的相对路径。

相对路径是可以追加到此引用(据此引用进行解析)以便定位第二个(参数)引用的组件的列表。使用“/”分隔符返回相对路径。

或者,相对路径可以包括“..”引用,但这样的路径将不能跨越明显的卷边界。

参数

ref:FileReference — 针对其给定该路径的 File 对象。
 
useDotDot:Boolean (default = false) — 指定生成的相对路径是否可以使用“..”组件。

返回
String — 如果可能,则为此文件(或目录)和 ref 文件(或目录)之间的相对路径;否则为 null

引发
ArgumentError — 该引用为 null
 
SecurityError — 调用方不在应用程序安全沙箱中。

    getRootDirectories

()方法 
public static function getRootDirectories():Array

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

返回 File 对象的数组,列出文件系统根目录。

例如在 Windows 中,这是一个卷列表,如 C: 驱动器和 D: 驱动器。此数组中不包括空的驱动器,如未插入光盘的 CD 或 DVD 驱动器。在 Mac OS 和 Linux 中,此方法始终返回计算机的唯一根目录(“/”目录)

在根不可读的文件系统上,例如 Android 文件系统,返回的 File 对象的属性并不总是反映真实值。例如,在 Android 上,spaceAvailable 属性报告 0。

返回
Array — File 对象的数组,列出各个根目录。

示例  ( 如何使用本示例 )

下面的代码输出根目录的列表:
import flash.filesystem.File;
var rootDirs:Array = File.getRootDirectories();

for (var i:uint = 0; i < rootDirs.length; i++) {
    trace(rootDirs[i].nativePath);
}

    moveTo

()方法 
public function moveTo(newLocation:FileReference, overwrite:Boolean = false):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

将此 File 对象指定的位置中的文件或目录移动到 destination 参数指定的位置。

要重命名文件,请将 destination 参数设置为指向该文件目录中的路径,但使用不同的文件名。

移动过程将创建任何需要的父级目录(如有可能)。

参数

newLocation:FileReference — 移动的目标位置。此对象指定生成(移动)的文件或目录的路径,不是 包含该文件或目录的目录的路径。
 
overwrite:Boolean (default = false) — 如果为 false,则当 target 文件已经存在时移动将失败。如果为 true,则该操作将覆盖任何现有的同名文件或目录。


引发
IOError — 源不存在;或者目标存在且 overwrite 设置为 false;或者无法将源文件或目录移动到目标位置;或者源和目标引用相同的文件或文件夹且 overwrite 设置为 true。在 Windows 中无法移动打开的文件,也无法移动包含已打开文件的目录。
 
SecurityError — 应用程序没有移动文件的必要权限。

相关 API 元素


示例  ( 如何使用本示例 )

下面的代码显示如何使用 moveTo() 方法重命名文件。原始文件名为 test1.txt,生成的文件名为 test2.txt。由于源和目标 File 对象都指向同一个目录(用户文档目录的 Apollo Test 子目录),moveTo() 方法将重命名该文件(而不是将它移动到新的目录中)。运行此代码之前,请在计算机上文档目录的 AIR Test 子目录中创建一个 test1.txt 文件。将 overwrite 参数设置为 true 时,此操作将覆盖任何现有的 test2.txt 文件。
import flash.filesystem.File;
import flash.events.Event;

var sourceFile:File = File.documentsDirectory;
sourceFile = sourceFile.resolvePath("AIR Test/test1.txt");
var destination:File = File.documentsDirectory;
destination = destination.resolvePath("Apollo Test/test2.txt");

try  
{
    sourceFile.moveTo(destination, true);
}
catch (error:Error)
{
    trace("Error:" + error.message);
}

下面的代码显示如何使用 moveTo() 方法移动文件。原始文件(test1.txt 文件)位于用户文档目录的 Apollo Test 子目录中,该方法将该文件移动到 Results 子目录中。运行此代码之前,在计算机上主目录的 AIR Test 子目录中创建一个 test1.txt 文件。trycatch 语句显示如何响应错误。
import flash.filesystem.File;

var sourceFile:File = File.documentsDirectory;
sourceFile = sourceFile.resolvePath("AIR Test/test1.txt");
var destination:File = File.documentsDirectory;
destination = destination.resolvePath("AIR Test/Results/test1.txt");

try 
{
    sourceFile.moveTo(destination, true);
}
catch (error:Error)
{
    trace("Error:" + error.message);
}

    moveToAsync

()方法 
public function moveToAsync(newLocation:FileReference, overwrite:Boolean = false):void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

开始将此 File 对象指定的位置中的文件或目录移动到 newLocation 参数指定的位置。

要重命名文件,请将 destination 参数设置为指向该文件目录中的路径,但使用不同的文件名。

移动过程将创建任何需要的父级目录(如有可能)。

参数

newLocation:FileReference — 移动的目标位置。此对象指定生成(移动)的文件或目录的路径,不是 包含该文件或目录的目录的路径。
 
overwrite:Boolean (default = false) — 如果为 false,则当 target 文件已经存在时移动将失败。如果为 true,则该操作将覆盖任何现有的同名文件或目录。


事件
complete:Event — 在文件或目录已成功移动时调度。
 
ioError:IOErrorEvent — 源不存在;或者目标存在而 overwritefalse;或者无法将源移动到目标;或者源和目标引用相同的文件或文件夹且 overwrite 设置为 true。在 Windows 中无法移动打开的文件,也无法移动包含已打开文件的目录。

引发
SecurityError — 应用程序没有移动文件的必要权限。

相关 API 元素


示例  ( 如何使用本示例 )

下面的代码显示如何使用 moveToAsync() 方法重命名文件。原始文件名为 test1.txt,生成的文件名为 test2.txt。由于源和目标 File 对象都指向同一个目录(用户文档目录的 Apollo Test 子目录),moveToAsync() 方法将重命名该文件(而不是将它移动到新的目录中)。在运行此代码之前,在计算机上文档目录的 Apollo Test 子目录中创建一个 test1.txt 文件。将 overwrite 参数设置为 true 时,此操作将覆盖任何现有的 test2.txt 文件。
import flash.filesystem.File;
import flash.events.Event;

var sourceFile:File = File.documentsDirectory;
sourceFile = sourceFile.resolvePath("Apollo Test/test1.txt");
var destination:File = File.documentsDirectory;
destination = destination.resolvePath("Apollo Test/test2.txt");

sourceFile.moveToAsync(destination, true);
sourceFile.addEventListener(Event.COMPLETE, fileMoveCompleteHandler);

function fileMoveCompleteHandler(event:Event):void 
{
    trace("Done.")
}

    moveToTrash

()方法 
public function moveToTrash():void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

将文件或目录移动到垃圾桶。

注意:在不支持可恢复垃圾桶文件夹概念的操作系统上,会立即删除文件。


引发
IOError — 操作系统不允许该操作;或者文件或目录不存在。在 Windows 中无法移动打开的文件,也无法移动包含当前打开的文件的目录。
 
SecurityError — 应用程序没有将文件移动到垃圾桶的必要权限。

相关 API 元素

    moveToTrashAsync

()方法 
public function moveToTrashAsync():void

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

将文件或目录异步移动到垃圾桶。

注意:在不支持可恢复垃圾桶文件夹概念的操作系统上,会立即删除文件。


事件
ioError:IOErrorEvent — 操作系统不允许该操作;或者文件或目录不存在。在 Windows 中无法移动打开的文件,也无法移动包含当前打开的文件的目录。
 
complete:Event — 在文件或目录已成功移动到垃圾桶时调度。

引发
SecurityError — 应用程序没有将文件移动到垃圾桶的必要权限。

相关 API 元素

    openWithDefaultApplication

()方法 
public function openWithDefaultApplication():void

语言版本: ActionScript 3.0
运行时版本: AIR 2

打开操作系统注册的应用程序中的文件来打开此类型的文件。

AIR 阻止您使用 File.openWithDefaultApplication() 方法打开特定文件。在 Windows 上,AIR 阻止您打开某些文件类型的文件(具有特定扩展名的文件,如下所示)。在 Mac OS 和 Linux 上,AIR 会阻止您打开在下面指定的特定应用程序中启动的文件。尝试使用 openWithDefaultApplication() 方法打开其中一个文件将导致异常。但是,使用本机安装程序(扩展的桌面配置文件应用程序)安装的 AIR 应用程序不受限于这些限制;它们可以打开任何类型的文件。

无法从应用程序目录中打开文档。

下列表列出了在 Windows 上禁止的文件扩展名,以及在 Mac OS 和 Linux 上阻止的应用程序:

Windows 文档扩展名 类型 Mac OS 应用程序对应项 Linux 应用程序对应项
bat 批处理文件命令 终端 无默认应用程序
cmd DOS 和 Windows 命令文件 终端 无默认应用程序
com 命令 终端 无默认应用程序
csh UNIX csh shell 脚本 终端 /bin/csh
短划线 UNIX dash shell 脚本 终端 /bin/dash
ksh UNIX ksh shell 脚本 终端 /bin/ksh
sh UNIX shell 脚本 终端 /bin/bash
tcsh UNIX tcsh shell 脚本 终端 /bin/tcsh
zsh UNIX zsh shell 脚本 终端 /bin/zsh
exe 可执行文件 可执行文件位,.app 扩展名 /lib/ld.so
lnk Windows 快捷方式文件 可执行文件位,.app 扩展名 Linux 中的链接,可执行位集,无默认应用程序
pif 程序信息文件 可执行文件位,.app 扩展名 不适用
reg 注册信息/Windows 注册表项数据文件 不适用 不适用
scf Windows 资源管理器命令 ScriptEditor、AutomatorRunner 不适用
shb, shs Shell 碎片对象文件 不适用 不适用
prg 程序文件 不适用 不适用
vb、vbe、vbs VBScript 文件 不适用 不适用
vsmacros 基于 Visual Studio .NET 二进制的宏项目 不适用 不适用
ws、wsc、wsf、wsh Windows 脚本文件 ScriptEditor、AutomatorRunner 不适用
fxp Fox Pro 编译的源代码 不适用 不适用
mas Microsoft Access 存储过程 不适用 不适用
scr Windows 屏幕保护程序 不适用 不适用
py、pyc Python 脚本文件 Python Python
pl Perl 脚本文件 终端 perl
cgi 通用网关接口脚本文件 终端 perl
msi、msm、msp、mst、idt、cub、pcp Windows 安装程序文件 安装程序 不适用
作业 Windows 任务计划程序任务对象 不适用 不适用
jar、js, jse Java 归档文件,JavaScript 文件,JScript 编码脚本文件 JarLauncher jar
url Internet 快捷方式 不适用 不适用
hta HTML 应用程序 不适用 不适用

仅限 Mac OS X 类型 Mac OS X 应用程序 Linux 应用程序对应项
不适用 Mac OS X Java 小程序 AppletLauncher 不适用
不适用 Mac OS X AppleScript 插件 systemevents 不适用
不适用 Mac OS X 小部件 停靠,dashboardlauncher 不适用

仅限 Linux 的文档扩展名 类型 Mac OS X 应用程序对应项 Linux 应用程序
rb Ruby shell 脚本 不适用 ruby
桌面 桌面文件和快捷方式 不适用 无默认应用程序
目录 目录文件和快捷方式 不适用 无默认应用程序


引发
Error — (Mac OS 和 Linux)未找到能打开此文件的应用程序。(在 Windows 上,试图打开无关联应用程序的文件失败,没有提示,也无异常发生。)
 
IllegalOperationError — 文件位于应用程序目录中,或文件类型属于是禁止的文件类型。此错误对于使用本机应用程序安装程序(扩展桌面配置文件应用程序)安装的 AIR 应用程序不适用。
 
IOError — 文件不存在或没有注册打开该文件的应用程序。
 
ReferenceError — 文件不存在。

相关 API 元素


示例  ( 如何使用本示例 )

使用以下代码,用户可导航到 MP3 文件并在播放 MP3 文件的默认应用程序中将其打开。
import flash.filesystem.File;
import flash.net.FileFilter;

var file:File = File.documentsDirectory; 
var mp3Filter:FileFilter = new FileFilter("MP3 Files", "*.mp3"); 
file.browseForOpen("Open", [mp3Filter]); 
file.addEventListener(Event.SELECT, fileSelected); 
 
function fileSelected(e:Event):void 
{ 
    file.openWithDefaultApplication(); 
}

    requestPermission

()方法 
override public function requestPermission():void

语言版本: ActionScript 3.0
运行时版本: AIR 24.0

申请文件系统访问权限


事件
PermissionStatus:PermissionEvent — 当用户授予/拒绝所申请权限时调度。

    resolvePath

()方法 
public function resolvePath(path:String):File

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

基于 path 参数(一个字符串)创建一个其路径相对于此 File 对象路径的新 File 对象。

path 参数可以使用相对路径或绝对路径。

如果指定相对路径,则将给定的 path“追加”到 File 对象的路径。但是,在 path 中使用“..”可以返回生成的路径(该路径不是 File 对象的子级)。生成的引用不必引用实际文件系统位置。

如果指定一个绝对文件引用,则该方法将返回指向该路径的 File 对象。绝对文件引用应使用对用户的操作系统有效的本机路径语法(例如 Windows 上的 "C:\\test")。不要将 URL(例如 "file:///c:/test")用作 path 参数。

所有生成的路径将按以下方式进行规范化:

  • 任何“.”元素都会被忽略。
  • 任何“..” 元素将参照其父级目录。
  • 任何到达文件系统根目录或应用程序的永久存储区根目录的“..”参照将无法越过该节点;将忽略此类参照。

应始终使用正斜杠 (/) 字符作为路径分隔符。在 Windows 上,也可以使用反斜杠 (\) 字符,但最好不要使用它。使用反斜杠字符可导致应用程序在其他平台上无法运行。

在 Linux 上,文件名和目录名是区分大小写的。

参数

path:String — 要追加到此 File 对象的路径中的路径(如果 path 参数为相对路径);或者要返回的路径(如果 path 参数为绝对路径)。

返回
File — 指向生成的路径的新 File 对象。
事件详细信息
    

cancel

事件
事件对象类型: flash.events.Event
属性 Event.type = flash.events.Event.CANCEL

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

在取消未处理的异步操作时调度。

Event.CANCEL 常量定义 cancel 事件对象的 type 属性的值。

此事件具有以下属性:

属性
bubblesfalse
cancelablefalse;没有要取消的默认行为。
currentTarget当前正在使用某个事件侦听器处理 Event 对象的对象。
target对已取消其操作的对象的引用。
    

complete

事件  
事件对象类型: flash.events.Event
属性 Event.type = flash.events.Event.COMPLETE

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

在异步操作完成时调度。

Event.COMPLETE 常量定义 complete 事件对象的 type 属性值。

此事件具有以下属性:

属性
bubblesfalse
cancelablefalse;没有要取消的默认行为。
currentTarget当前正在使用某个事件侦听器处理 Event 对象的对象。
target已完成加载的网络对象。
    

directoryListing

事件  
事件对象类型: flash.events.FileListEvent
属性 FileListEvent.type = flash.events.FileListEvent.DIRECTORY_LISTING

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

当由于调用 getDirectoryListingAsync() 方法而提供目录列表时调度。

FileListEvent.DIRECTORY_LISTING 常量定义 directoryListing 事件的事件对象的 type 属性值。

此事件具有以下属性:

属性
bubblesfalse
cancelablefalse;没有要取消的默认行为。
files表示找到的文件和目录的 File 对象的数组。
targetFileListEvent 对象。

相关 API 元素

    

ioError

事件  
事件对象类型: flash.events.IOErrorEvent
属性 IOErrorEvent.type = flash.events.IOErrorEvent.IO_ERROR

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

在执行异步文件操作期间发生错误时调度。

定义 ioError 事件对象的 type 属性值。

此事件具有以下属性:

属性
bubblesfalse
cancelablefalse;没有要取消的默认行为。
currentTarget当前正在使用某个事件侦听器处理 Event 对象的对象。
errorID与特定错误关联的引用编号(仅限 AIR)。
target发生输入/输出错误的网络对象。
text要显示为错误消息的文本。
    

permissionStatus

事件  
事件对象类型: flash.events.PermissionEvent
属性 PermissionEvent.type = flash.events.PermissionEvent.PERMISSION_STATUS

语言版本: ActionScript 3.0
运行时版本: AIR 24.0

当应用程序申请文件系统访问权限时调度。检查 status 属性的值,以确定是授予此权限还是拒绝此权限。

相关 API 元素

    

securityError

事件  
事件对象类型: flash.events.SecurityErrorEvent
属性 SecurityErrorEvent.type = flash.events.SecurityErrorEvent.SECURITY_ERROR

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

当操作违反安全限制时调度。

SecurityErrorEvent.SECURITY_ERROR 常量定义 securityError 事件对象的 type 属性值。

此事件具有以下属性:

属性
bubblesfalse
cancelablefalse;没有要取消的默认行为。
currentTarget当前正在使用某个事件侦听器处理 Event 对象的对象。
target报告安全错误的网络对象。
text要显示为错误消息的文本。
    

select

事件  
事件对象类型: flash.events.Event
属性 Event.type = flash.events.Event.SELECT

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

当用户从文件浏览或目录浏览对话框中选择文件或目录时调度。

Event.SELECT 常量定义 select 事件对象的 type 属性的值。

此事件具有以下属性:

属性
bubblesfalse
cancelablefalse;没有要取消的默认行为。
currentTarget当前正在使用某个事件侦听器处理 Event 对象的对象。
target 对象,已在其中选定了一个项目。
    

selectMultiple

事件  
事件对象类型: flash.events.FileListEvent
属性 FileListEvent.type = flash.events.FileListEvent.SELECT_MULTIPLE

语言版本: ActionScript 3.0
运行时版本: AIR 1.0

当用户从通过调用 browseForOpenMultiple() 方法打开的对话框中选择文件时调度。

FileListEvent.SELECT_MULTIPLE 常量定义 selectMultiple 事件的事件对象的 type 属性值。
属性
bubblesfalse
cancelablefalse;没有要取消的默认行为。
files表示所选文件的 File 对象的数组。
targetFileListEvent 对象。

相关 API 元素





[ X ]为什么显示为英语?
《ActionScript 3.0 参考》中的内容以英语显示

《ActionScript 3.0 参考》中的部分内容未翻译成所有语言。当某个语言元素未翻译时,将显示为英语。例如,ga.controls.HelpBox 类未翻译成任何语言。因此在简体中文版的参考中,ga.controls.HelpBox 类显示为英语。