AI2 Component  (Version nb184)
com.google.appinventor.components.runtime.util.FileUtil Class Reference

Classes

class  FileException
 

Static Public Member Functions

static String getFileUrl (String localFileName)
 
static byte[] readFile (String inputFileName) throws IOException
 
static byte[] readFile (Form form, String inputFileName) throws IOException
 
static FileInputStream openFile (String fileName) throws IOException, PermissionException
 
static FileInputStream openFile (Form form, String fileName) throws IOException, PermissionException
 
static FileInputStream openFile (File file) throws IOException, PermissionException
 
static FileInputStream openFile (Form form, File file) throws IOException, PermissionException
 
static FileInputStream openFile (URI fileUri) throws IOException, PermissionException
 
static FileInputStream openFile (Form form, URI fileUri) throws IOException, PermissionException
 
static String downloadUrlToFile (String url, String outputFileName) throws IOException
 
static String writeFile (byte[] array, String outputFileName) throws IOException
 
static String copyFile (String inputFileName, String outputFileName) throws IOException
 
static String writeStreamToFile (InputStream in, String outputFileName) throws IOException
 
static File getPictureFile (String extension) throws IOException, FileException
 
static File getPictureFile (Form form, String extension) throws IOException, FileException
 
static File getRecordingFile (String extension) throws IOException, FileException
 
static File getRecordingFile (Form form, String extension) throws IOException, FileException
 
static File getDownloadFile (String extension) throws IOException, FileException
 
static File getDownloadFile (Form form, String extension) throws IOException, FileException
 
static File getExternalFile (String fileName) throws IOException, FileException, SecurityException
 
static File getExternalFile (Form form, String fileName) throws IOException, FileException, SecurityException
 
static void checkExternalStorageWriteable () throws FileException
 

Detailed Description

Utilities for reading and writing files to the external storage.

Author
lizlo.nosp@m.oney.nosp@m.@goog.nosp@m.le.c.nosp@m.om (Liz Looney)

Definition at line 37 of file FileUtil.java.

Member Function Documentation

◆ checkExternalStorageWriteable()

static void com.google.appinventor.components.runtime.util.FileUtil.checkExternalStorageWriteable ( ) throws FileException
static

Definition at line 561 of file FileUtil.java.

◆ copyFile()

static String com.google.appinventor.components.runtime.util.FileUtil.copyFile ( String  inputFileName,
String  outputFileName 
) throws IOException
static

Copies the contents of one local file to another local file.

Parameters
inputFileNamethe name of the file to read to
outputFileNamethe name of the file to write to
Returns
the URL for the local file

Definition at line 307 of file FileUtil.java.

◆ downloadUrlToFile()

static String com.google.appinventor.components.runtime.util.FileUtil.downloadUrlToFile ( String  url,
String  outputFileName 
) throws IOException
static

Downloads the resource with the given URL and writes it as a local file.

Parameters
urlthe URL to read from
outputFileNamethe name of the file to write to
Returns
the URL for the local file

Definition at line 275 of file FileUtil.java.

◆ getDownloadFile() [1/2]

static File com.google.appinventor.components.runtime.util.FileUtil.getDownloadFile ( Form  form,
String  extension 
) throws IOException, FileException
static

Creates a File representing the complete path for a downloaded file, creating the enclosing directories if needed. This does not actually open the file. Any component that calls this must have android.Manifest.permission#WRITE_EXTERNAL_STORAGE.

Parameters
formthe form to use as an Android context
extensionfile extension, such as "tmp"
Returns
the path to the file
Exceptions
IOExceptionif the enclosing directory cannot be created
FileExceptionif external storage is not accessible or not writable with the appropriate ErrorMessages error code.

Definition at line 477 of file FileUtil.java.

◆ getDownloadFile() [2/2]

static File com.google.appinventor.components.runtime.util.FileUtil.getDownloadFile ( String  extension) throws IOException, FileException
static

Creates a File representing the complete path for a downloaded file, creating the enclosing directories if needed. This does not actually open the file. Any component that calls this must have android.Manifest.permission#WRITE_EXTERNAL_STORAGE.

This function is deprecated. Developers should use getDownloadFile(Form, String) instead.

Returns
the path to the file
Parameters
extensionfile extension, such as "tmp"
Exceptions
IOExceptionif the enclosing directory cannot be created
FileExceptionif external storage is not accessible or not writable with the appropriate ErrorMessages error code.

Definition at line 458 of file FileUtil.java.

◆ getExternalFile() [1/2]

static File com.google.appinventor.components.runtime.util.FileUtil.getExternalFile ( Form  form,
String  fileName 
) throws IOException, FileException, SecurityException
static

Returns the File for fileName in the external storage directory in preparation for writing the file. fileName may contain sub-directories. Ensures that all subdirectories exist and that fileName does not exist (deleting it if necessary).

Parameters
formthe form to use as an Android context
fileNameThe path name of the file relative to the external storage directory
Returns
the File object for creating fileName in the external storage
Exceptions
IOExceptionif we are unable to create necessary parent directories or delete an existing file
FileExceptionif the external storage is not writeable.

Definition at line 538 of file FileUtil.java.

◆ getExternalFile() [2/2]

static File com.google.appinventor.components.runtime.util.FileUtil.getExternalFile ( String  fileName) throws IOException, FileException, SecurityException
static

Returns the File for fileName in the external storage directory in preparation for writing the file. fileName may contain sub-directories. Ensures that all subdirectories exist and that fileName does not exist (deleting it if necessary).

This function is deprecated. Developers should use getExternalFile(Form, String) instead.

Parameters
fileNameThe path name of the file relative to the external storage directory
Returns
the File object for creating fileName in the external storage
Exceptions
IOExceptionif we are unable to create necessary parent directories or delete an existing file
FileExceptionif the external storage is not writeable.

Definition at line 519 of file FileUtil.java.

◆ getFileUrl()

static String com.google.appinventor.components.runtime.util.FileUtil.getFileUrl ( String  localFileName)
static

Returns an URL for the given local file.

Definition at line 64 of file FileUtil.java.

◆ getPictureFile() [1/2]

static File com.google.appinventor.components.runtime.util.FileUtil.getPictureFile ( Form  form,
String  extension 
) throws IOException, FileException
static

Creates a File representing the complete path for an image file, creating the enclosing directories if needed. This does not actually open the file. Any component that calls this must have android.Manifest.permission#WRITE_EXTERNAL_STORAGE.

Parameters
formthe form to use as an Android context
extensionfile extension, such as "png" or "jpg"
Returns
the path to the file
Exceptions
IOExceptionif the enclosing directory cannot be created
FileExceptionif external storage is not accessible or not writable with the appropriate ErrorMessages error code.

Definition at line 394 of file FileUtil.java.

◆ getPictureFile() [2/2]

static File com.google.appinventor.components.runtime.util.FileUtil.getPictureFile ( String  extension) throws IOException, FileException
static

Creates a File representing the complete path for an image file, creating the enclosing directories if needed. This does not actually open the file. Any component that calls this must have android.Manifest.permission#WRITE_EXTERNAL_STORAGE.

This function is deprecrated. Developers should use getPictureFile(Form, String) instead.

Parameters
extensionfile extension, such as "png" or "jpg"
Returns
the path to the file
Exceptions
IOExceptionif the enclosing directory cannot be created
FileExceptionif external storage is not accessible or not writable with the appropriate ErrorMessages error code.

Definition at line 375 of file FileUtil.java.

◆ getRecordingFile() [1/2]

static File com.google.appinventor.components.runtime.util.FileUtil.getRecordingFile ( Form  form,
String  extension 
) throws IOException, FileException
static

Creates a File representing the complete path for a recording, creating the enclosing directories if needed. This does not actually open the file. Any component that calls this must have android.Manifest.permission#WRITE_EXTERNAL_STORAGE.

Parameters
formthe form to use as an Android context
extensionfile extension, such as "3gp"
Returns
the path to the file
Exceptions
IOExceptionif the enclosing directory cannot be created
FileExceptionif external storage is not accessible or not writable with the appropriate ErrorMessages error code.

Definition at line 435 of file FileUtil.java.

◆ getRecordingFile() [2/2]

static File com.google.appinventor.components.runtime.util.FileUtil.getRecordingFile ( String  extension) throws IOException, FileException
static

Creates a File representing the complete path for a recording, creating the enclosing directories if needed. This does not actually open the file. Any component that calls this must have android.Manifest.permission#WRITE_EXTERNAL_STORAGE.

This function is deprecated. Developers should use getRecordingFile(Form, String) instead.

Returns
the path to the file
Parameters
extensionfile extension, such as "3gp"
Exceptions
IOExceptionif the enclosing directory cannot be created
FileExceptionif external storage is not accessible or not writable with the appropriate ErrorMessages error code.

Definition at line 417 of file FileUtil.java.

◆ openFile() [1/6]

static FileInputStream com.google.appinventor.components.runtime.util.FileUtil.openFile ( File  file) throws IOException, PermissionException
static

Opens the file identified by the given File object.

If the file is an external file and the app is running on a version of Android at SDK level 23 or higher, then the READ_EXTERNAL_STORAGE permission will be checked. If the app does not have permission to read the external file, a PermissionException will be thrown.

This function is deprecated. Developers should use openFile(Form, File) instead.

Parameters
fileThe file to open.
Returns
An open FileInputStream on success
Exceptions
IOExceptionIf the file cannot be opened
PermissionExceptionIf the app does not have permission to read external files and the pathname looks to be external.

Definition at line 193 of file FileUtil.java.

◆ openFile() [2/6]

static FileInputStream com.google.appinventor.components.runtime.util.FileUtil.openFile ( Form  form,
File  file 
) throws IOException, PermissionException
static

Opens the file identified by the given File object.

If the file is an external file and the app is running on a version of Android at SDK level 23 or higher, then the READ_EXTERNAL_STORAGE permission will be checked. If the app does not have permission to read the external file, a PermissionException will be thrown.

Parameters
formthe form to use as an Android context
fileThe file to open.
Returns
An open FileInputStream on success
Exceptions
IOExceptionIf the file cannot be opened
PermissionExceptionIf the app does not have permission to read external files and the pathname looks to be external.

Definition at line 214 of file FileUtil.java.

◆ openFile() [3/6]

static FileInputStream com.google.appinventor.components.runtime.util.FileUtil.openFile ( Form  form,
String  fileName 
) throws IOException, PermissionException
static

Opens the file at the given file name.

If the file is an external file and the app is running on a version of Android at SDK level 23 or higher, then the READ_EXTERNAL_STORAGE permission will be checked. If the app does not have permission to read the external file, a PermissionException will be thrown.

Parameters
formthe form to use as an Android context
fileNameThe file path to open.
Returns
An open FileInputStream on success
Exceptions
IOExceptionIf the file cannot be opened
PermissionExceptionIf the app does not have permission to read external files and the pathname looks to be external.

Definition at line 165 of file FileUtil.java.

◆ openFile() [4/6]

static FileInputStream com.google.appinventor.components.runtime.util.FileUtil.openFile ( Form  form,
URI  fileUri 
) throws IOException, PermissionException
static

Opens the file at the given file URI.

If the file is an external file and the app is running on a version of Android at SDK level 23 or higher, then the READ_EXTERNAL_STORAGE permission will be checked. If the app does not have permission to read the external file, a PermissionException will be thrown.

Parameters
formthe form to use as an Android context
fileUriThe file URI to open.
Returns
An open FileInputStream on success
Exceptions
IOExceptionIf the file cannot be opened
PermissionExceptionIf the app does not have permission to read external files and the pathname looks to be external.

Definition at line 260 of file FileUtil.java.

◆ openFile() [5/6]

static FileInputStream com.google.appinventor.components.runtime.util.FileUtil.openFile ( String  fileName) throws IOException, PermissionException
static

Opens the file at the given file name.

If the file is an external file and the app is running on a version of Android at SDK level 23 or higher, then the READ_EXTERNAL_STORAGE permission will be checked. If the app does not have permission to read the external file, a PermissionException will be thrown.

This function is deprecated. Developers should use openFile(Form, String) instead.

Parameters
fileNameThe file path to open.
Returns
An open FileInputStream on success
Exceptions
IOExceptionIf the file cannot be opened
PermissionExceptionIf the app does not have permission to read external files and the pathname looks to be external.

Definition at line 144 of file FileUtil.java.

◆ openFile() [6/6]

static FileInputStream com.google.appinventor.components.runtime.util.FileUtil.openFile ( URI  fileUri) throws IOException, PermissionException
static

Opens the file at the given file URI.

If the file is an external file and the app is running on a version of Android at SDK level 23 or higher, then the READ_EXTERNAL_STORAGE permission will be checked. If the app does not have permission to read the external file, a PermissionException will be thrown.

This function is deprecated. Developers should use openFile(Form, URI) instead.

Parameters
fileUriThe file URI to open.
Returns
An open FileInputStream on success
Exceptions
IOExceptionIf the file cannot be opened
PermissionExceptionIf the app does not have permission to read external files and the pathname looks to be external.

Definition at line 239 of file FileUtil.java.

◆ readFile() [1/2]

static byte [] com.google.appinventor.components.runtime.util.FileUtil.readFile ( Form  form,
String  inputFileName 
) throws IOException
static

Reads the given local file and returns the contents as a byte array.

Parameters
formthe form to use as an Android context
inputFileNamethe name of the file to read from
Returns
the file's contents as a byte array

Definition at line 91 of file FileUtil.java.

◆ readFile() [2/2]

static byte [] com.google.appinventor.components.runtime.util.FileUtil.readFile ( String  inputFileName) throws IOException
static

Reads the given local file and returns the contents as a byte array.

This function is deprecated. Developers should use readFile(Form, String) instead.

Parameters
inputFileNamethe name of the file to read from
Returns
the file's contents as a byte array

Definition at line 79 of file FileUtil.java.

◆ writeFile()

static String com.google.appinventor.components.runtime.util.FileUtil.writeFile ( byte[]  array,
String  outputFileName 
) throws IOException
static

Writes the given byte array as a local file.

Parameters
arraythe byte array to read from
outputFileNamethe name of the file to write to
Returns
the URL for the local file

Definition at line 291 of file FileUtil.java.

◆ writeStreamToFile()

static String com.google.appinventor.components.runtime.util.FileUtil.writeStreamToFile ( InputStream  in,
String  outputFileName 
) throws IOException
static

Writes the contents from the given input stream to the given file.

Parameters
inthe InputStream to read from
outputFileNamethe name of the file to write to
Returns
the URL for the local file

Definition at line 324 of file FileUtil.java.


The documentation for this class was generated from the following file: