File CLASS

This class represents a file as defined by the underlying file system.

Parent Class

Parent Interfaces

All Members


TypeNameSignature
constructorFilepublic File(string)
methodcreatepublic bool create()
methoddeletepublic bool delete()
methodexistspublic bool exists()
methodgetNamepublic String getName()
methodgetParentpublic Directory getParent()
methodgetPathpublic String getPath()
methodgetReadStreampublic Stream getReadStream()
methodgetWriteStreampublic Stream getWriteStream(bool)
methodisFilepublic bool isFile()
methodmovepublic bool move(System.IO.Directory)
methodreadAllTextpublic String readAllText()
methodrenamepublic bool rename(string)

Constructors


public File(string path)

Create a new file with the specified path.

Parameters

  • path The path to this file. If this is a relative path, it will be resolved against current working directory.

Methods


public bool create()

Create a file represented by this object.

Required Policies

  • System.IO/write

Returns

  • True if the file was created; false if the file already exists.

Throws


public bool delete()

Delete this file.

Required Policies

  • System.IO/write

Returns

  • True if the file was successfully deleted; false if the file didn't exist.

Throws


public bool exists()

Whether this file exist on file system.

Required Policies

  • System.IO/stat

Returns

  • True if the file exists.

public String getName()

Get the name of this file. This is only the simple name (with extension) on the path.

Required Policies

  • System.IO/stat

Returns

  • The file's name

public Directory getParent()

Get the directory this file resides in.

Required Policies

  • System.IO/stat

Returns

  • The parent directory. Or null if the path doesn't exist.

Throws


public String getPath()

Get the absolute path of this file, including the name.

Required Policies

  • System.IO/stat

Returns

  • The file's path, including the name. Note this can be different from the path used by the constructor, which could take a relative path.

public Stream getReadStream()

Get a stream to read from this file.

Access policy System.IO/read must be enabled to perform read operation on this stream.

Returns

  • A stream that supports reading (both synchronously and asynchronously) but not writing or marking.

See Also


public Stream getWriteStream(bool append)

Get a stream to write into this file.

Access policy System.IO/write must be enabled to perform write operation on this stream.

Parameters

  • append

Returns

  • A stream that supports writing but not reading or marking.

See Also


public bool isFile()

Always return true.

Returns

  • true

public bool move(Directory newDir)

(INHERITED DOC)

Move this item to another directory.

Unlike a few file systems where the move command/API serves dual purpose, Julian splits the semantics between move and rename. Rename operation is only for renaming without moving around the file, while this method may only be used to move an item from one directory to another without changing its name. The obvious implication of this division is that for the move operation, the destination must be a valid directory, and there must be no item in that directory that is already possessing the same name. In any of these cases this method returns false. Moving to the same directory is allowed and implemented trivially by returning true directly.

To move an item and change its name, use extension method relocate().

Required Policies

  • System.IO/write

Parameters

  • newDir The new directory.

Returns

  • True if the file was successfully moved; false if the file couldn't be.

public String readAllText()

Read all the contents from this file as text. This is a rather convenient method for quick scripting, but won't scale well if the file is too large and the operation is too frequent. When dealing with reading large files at high frequency, always consider using an asynchronous stream first.

Required Policies

  • System.IO/read

Returns

  • The contents from this file, in the format of plain ASCII text.

public bool rename(string newName)

(INHERITED DOC)

Rename this item while remaining in the same directory.

Unlike a few file systems where the move command/API serves dual purpose, Julian splits the semantics between move and rename. Move operation may only be used to move an item from one directory to another without changing its name, while this method is only for renaming without moving around the file. The obvious implication of this division is that for the rename operation, the new name must not contain file system separator, and there must be no item within the same directory that is already possessing the same name. In any of these cases this method returns false.

To move an item and change its name, use extension method relocate().

Required Policies

  • System.IO/write

Parameters

  • newName The new file name. Must not contain FS separator.

Returns

  • True if the file was successfully renamed; false if the file couldn't be.