For the fileMode parameter, specify a constant from the FileMode class that specifies the way in which you will use the file. For example, the following code initializes a FileStream object that is used to create a file and overwrite any existing data:.
For more information, see Initializing a FileStream object, and opening and closing files and FileStream open modes. These event listener methods respond to events dispatched by the FileStream object in various situations. For details, see Asynchronous programming and the events generated by a FileStream object opened asynchronously.
There are many methods of the FileStream class related to reading and writing. They each begin with "read" or "write". The method you choose to use to read or write data depends on the format of the data in the target file. If you want to deal with the data as byte arrays, you may use the readByte , readBytes , writeByte , and writeBytes methods. For details, see Data formats, and choosing the read and write methods to use.
If you opened the file asynchronously, then be sure that enough data is available before calling a read method. You can reference this directory using the File. You can use this directory to examine the application descriptor file or other resources installed with the application.
For example, the following code points a File object to a directory named images in the application directory:. This directory contains temporary files that are not required for the application to run and will not cause problems or data loss for the user if they are deleted.
In most operating systems the cache directory is a temporary directory. For more information, see Controlling file backup and caching. The File. The StorageVolumeInfo. You can point the File object to an explicit directory by setting the nativePath property of the File object, as in the following example on Windows :.
Important: Pointing to an explicit path this way can lead to code that does not work across platforms. For example, the previous example only works on Windows. You can use the static properties of the File object, such as File.
Then use the resolvePath method see the next section to navigate to a relative path. You can use the resolvePath method to obtain a path relative to another given path. For example, the following code sets a File object to point to an "AIR Test" subdirectory of the user's home directory:.
You can also use the url property of a File object to point it to a directory based on a URL string, as in the following:. For more information, see Modifying File paths. The File class includes the browseForDirectory method, which presents a system dialog box in which the user can select a directory to assign to the object.
The browseForDirectory method is asynchronous. The File object dispatches a select event if the user selects a directory and clicks the Open button, or it dispatches a cancel event if the user clicks the Cancel button. For example, the following code lets the user select a directory and outputs the directory path upon selection:. You can get the directory location from which an application is invoked, by checking the currentDirectory property of the InvokeEvent object dispatched when the application is invoked.
For details, see Capturing command line arguments. Important: Pointing to an explicit path can lead to code that does not work across platforms. Then use the resolvePath method see Modifying File paths to navigate to a relative path.
You can use the url property of a File object to point it to a file or directory based on a URL string, as in the following:. You can also pass the URL to the File constructor function, as in the following:. You can also use the nativePath property of a File object to set an explicit path. For example, the following code, when run on a Windows computer, sets a File object to the test. You can also pass this path to the File constructor function, as in the following:.
You can use the getDirectoryListing method of a File object to get an array of File objects pointing to files and subdirectories at the root level of a directory.
For more information, see Enumerating directories. The File class includes the following methods that present a system dialog box in which the user can select a file to assign to the object:. These methods are each asynchronous. The browseForOpen and browseForSave methods dispatch the select event when the user selects a file or a target path, in the case of browseForSave.
With the browseForOpen and browseForSave methods, upon selection the target File object points to the selected files. The browseForOpenMultiple method dispatches a selectMultiple event when the user selects files. The selectMultiple event is of type FileListEvent, which has a files property that is an array of File objects pointing to the selected files.
If the application has another browser dialog box open when you call a browse method, the runtime throws an Error exception. You can also modify the path of an existing File object by calling the resolvePath method or by modifying the nativePath or url property of the object, as in the following examples on Windows :.
Use to specify a path relative to the root directory of the installed application the directory that contains the application. For example, the following path points to an images subdirectory of the directory of the installed application:. Use to specify a path relative to the application store directory. For each installed application, AIR defines a unique application store directory, which is a useful place to store data specific to that application.
For example, the following path points to a prefs. Certain operating systems, most notably iOS and Mac OS X, provide users the ability to automatically back up application files to a remote storage. In addition, on iOS there are restrictions on whether files can be backed up and also where files of different purposes can be stored. For further information see the next sections. To specify that a file does not need to be backed up and iOS only can be deleted by the operating system if device storage space runs low, save the file in the cache directory File.
This is the preferred storage location on iOS and should be used for most files that can be regenerated or re-downloaded. To specify that a file does not need to be backed up, but should not be deleted by the operating system, save the file in one of the application library directories such as the application storage directory File.
This is required by Apple for content that can be regenerated or downloaded again, but which is required for proper functioning of your application during offline use. By default all files in the application library folders are backed up. On Mac OS X this is the application storage directory. On iOS, this includes the application storage directory, the application directory, the desktop directory, documents directory, and user directory because those directories are mapped to application library folders on iOS.
Consequently, any files in those directories are backed up to server storage by default. If you are saving a file in one of those locations that can be re-created by your application, you should flag the file so the operating system knows not to back it up. On iOS, files in the application library folders such as the application storage directory or the documents directory are flagged as permanent and are not deleted by the operating system. Save files that can be regenerated by the application and are safe to delete in case of low storage space in the application cache directory.
You access the cache directory using the File. On other operating systems, this directory is mapped to a comparable directory. On Windows, the cache directory maps to the operating system temp directory.
You can use the getRelativePath method to find the relative path between two files:. The second parameter of the getRelativePath method, the useDotDot parameter, allows for.. File and path names are not case sensitive on Windows and Mac OS. In the following, two File objects point to the same file:. However, documents and directory names do include capitalization. I can't write to file which is on external sd card not on internal sd card.
Please help me. I have the external permission, and writing directly to the File. However, when I try this on a subfolder on the sdcard, I get the access denied error. Any ideas? I tried unplugging the USB as mentioned above but it didn't help. Hi, I want to download video from the url and save to sd card.
Can you tell me is that possible? Thank you for such a very good tips. It will help a lot. Adobe Support. If you're even slightly serious about making an income from the internet, this is something you can't ignore Simplest way, install this free file browser and navigate to your sdcard.
You will read path on the top. Hello Friends, Use this magnificent converter for aif file, mov file, or mp4 file, Unique Converter. The other night I ended up banging my head against the wall wondering why I couldn't write a file or even create a directory for that matter to my Samsung Galaxy S filesystem using a Flex application running on Adobe AIR. The code was simple enough and apparently the code should have worked on my mobile without any additional changes.
However, when things didn't work I was left stumped.
0コメント