Android Guides | Samples

Java.IO.File Class

An "abstract" representation of a file system entity identified by a pathname.

See Also: File

Syntax

[Android.Runtime.Register("java/io/File", DoNotGenerateAcw=true)]
public class File : Object, ISerializable, IComparable, IDisposable

Remarks

An "abstract" representation of a file system entity identified by a pathname. The pathname may be absolute (relative to the root directory of the file system) or relative to the current directory in which the program is running.

The actual file referenced by a File may or may not exist. It may also, despite the name File, be a directory or other non-regular file.

This class provides limited functionality for getting/setting file permissions, file type, and last modified time.

On Android strings are converted to UTF-8 byte sequences when sending filenames to the operating system, and byte sequences returned by the operating system (from the various list methods) are converted to strings by decoding them as UTF-8 byte sequences.

See Also

[Android Documentation]

Requirements

Namespace: Java.IO
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1

The members of Java.IO.File are listed below.

See Also: Object

Public Constructors

Constructs a new File using the path of the specified URI.
Constructs a new file using the specified path.
Constructs a new file using the specified directory and name.
Constructs a new File using the specified directory path and file name, placing a path separator between the two.

Protected Constructors

A constructor used when creating managed representations of JNI objects; called by the runtime.

Public Properties

[read-only]
AbsoluteFileFile. Returns a new file constructed using the absolute path of this file.
[read-only]
AbsolutePathString. Returns the absolute path of this file.
[read-only]
CanonicalFileFile. Returns a new file created using the canonical path of this file.
[read-only]
CanonicalPathString. Returns the canonical path of this file.
[read-only]
FreeSpaceInt64. Returns the number of free bytes on the partition containing this path.
[read-only]
IsAbsoluteBoolean. Indicates if this file's pathname is absolute.
[read-only]
IsDirectoryBoolean. Indicates if this file represents a directory on the underlying file system.
[read-only]
IsFileBoolean. Indicates if this file represents a file on the underlying file system.
[read-only]
IsHiddenBoolean. Returns whether or not this file is a hidden file as defined by the operating system.
[read-only]
NameString. Returns the name of the file or directory represented by this file.
[read-only]
ParentString. Returns the pathname of the parent of this file.
[read-only]
ParentFileFile. Returns a new file made from the pathname of the parent of this file.
[read-only]
PathString. Returns the path of this file.
[read-only]
static
PathSeparatorString. The system-dependent string used to separate components in search paths (":").
[read-only]
static
PathSeparatorCharChar. The system-dependent character used to separate components in search paths (':').
[read-only]
static
SeparatorString. The system-dependent string used to separate components in filenames ('/').
[read-only]
static
SeparatorCharChar. The system-dependent character used to separate components in filenames ('/').
[read-only]
TotalSpaceInt64. Returns the total size in bytes of the partition containing this path.
[read-only]
UsableSpaceInt64. Returns the number of usable free bytes on the partition containing this path.

Protected Properties

[read-only]
override
ThresholdClassIntPtr. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.
[read-only]
override
ThresholdTypeType. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Public Methods

CanExecute() : Boolean
Tests whether or not this process is allowed to execute this file.
CanRead() : Boolean
Indicates whether the current context is allowed to read from this file.
CanWrite() : Boolean
Indicates whether the current context is allowed to write to this file.
CompareTo(File) : Int32
Returns the relative sort ordering of the paths for this file and the file another.
CreateNewFile() : Boolean
Creates a new, empty file on the file system according to the path information stored in this file.
static
CreateTempFile(String, String) : File
Creates an empty temporary file using the given prefix and suffix as part of the file name.
static
CreateTempFile(String, String, File) : File
Creates an empty temporary file in the given directory using the given prefix and suffix as part of the file name.
Delete() : Boolean
Deletes this file.
DeleteOnExit()
Schedules this file to be automatically deleted when the VM terminates normally.
Exists() : Boolean
Returns a boolean indicating whether this file can be found on the underlying file system.
LastModified() : Int64
Returns the time when this file was last modified, measured in milliseconds since January 1st, 1970, midnight.
Length() : Int64
Returns the length of this file in bytes.
List() : String[]
Returns an array of strings with the file names in the directory represented by this file.
List(IFilenameFilter) : String[]
Gets a list of the files in the directory represented by this file.
ListAsync() : System.Threading.Tasks.Task<String[]>
ListAsync(IFilenameFilter) : System.Threading.Tasks.Task<String[]>
ListFiles() : File[]
Returns an array of files contained in the directory represented by this file.
ListFiles(IFileFilter) : File[]
Gets a list of the files in the directory represented by this file.
ListFiles(IFilenameFilter) : File[]
Gets a list of the files in the directory represented by this file.
ListFilesAsync() : System.Threading.Tasks.Task<File[]>
ListFilesAsync(IFileFilter) : System.Threading.Tasks.Task<File[]>
ListFilesAsync(IFilenameFilter) : System.Threading.Tasks.Task<File[]>
static
ListRoots() : File[]
Returns the file system roots.
static
ListRootsAsync() : System.Threading.Tasks.Task<File[]>
Mkdir() : Boolean
Creates the directory named by this file, assuming its parents exist.
Mkdirs() : Boolean
Creates the directory named by this file, creating missing parent directories if necessary.
RenameTo(File) : Boolean
Renames this file to newPath.
SetExecutable(Boolean) : Boolean
Equivalent to setExecutable(executable, true).
SetExecutable(Boolean, Boolean) : Boolean
Manipulates the execute permissions for the abstract path designated by this file.
SetLastModified(Int64) : Boolean
Sets the time this file was last modified, measured in milliseconds since January 1st, 1970, midnight.
SetReadable(Boolean) : Boolean
Equivalent to setReadable(readable, true).
SetReadable(Boolean, Boolean) : Boolean
Manipulates the read permissions for the abstract path designated by this file.
SetReadOnly() : Boolean
Equivalent to setWritable(false, false).
SetWritable(Boolean) : Boolean
Equivalent to setWritable(writable, true).
SetWritable(Boolean, Boolean) : Boolean
Manipulates the write permissions for the abstract path designated by this file.
ToURI() : URI
Returns a Uniform Resource Identifier for this file.
ToURL() : URL
Returns a Uniform Resource Locator for this file.

Explicitly Implemented Interface Members