Home > Contents > Index >
Expanded TOC   |    Accordion TOC   |    Annotated TOC   |    Index

 

Utilities.readFile

Reads a specified file and either returns its contents or writes the bytes to the I/O stream.

This method has three variants:


Utilities.readFile

Reads the specified file and returns its contents.

Syntax

Parameters

pathname
The pathname of the file to read.

Description

The readFile method reads the file indicated by the passed file path, and returns its contents. The path is internally converted by osSafeSpec(). The method assumes that the character of the file are in the default encoding. (The default encoding is set by the Java VM.)

Returns

If successful, the method returns the contents of the file. If unsuccessful, the method returns null.

Throws

IOException
If the method could not read from pathname or write to os. Common reasons for failure include the following:

Example

The following example reads and displays the contents of file D:/java/sonnet.txt. The code assumes that the contents of this file are in the default encoding:

See Also

osSafeSpec


Utilities.readFile

Reads the specified file and returns its contents. Specify the encoding of the input file.

Syntax

Parameters

pathname
The pathname of the file to read.

encoding
Specify the encoding of the contents of the file at pathname. Typical encoding values include "UTF-8" or "Latin-1".

Description

The previous variant of readfile assumes that the contents of pathname are in the default encoding (which is set by the Java VM). By contrast, Variant 2 or readfile allows you to specify the encoding.

Returns

If successful, the method returns the contents of the file. If unsuccessful, the method returns null.

Throws

IOException
If the method could not read from pathname or write to os. Common reasons for failure include the following:

See Also

osSafeSpec


Utilities.readFile

Reads the file indicated by the passed file path and writes the bytes to the output stream.

Syntax

Parameters

pathname
The pathname of the file to read.

os
The output stream to which this method should write the contents of the file.

Description

This readFile method reads the file indicated by the passed pathname, and writes its contents to the specified output stream. The path is internally converted by osSafeSpec().

Returns

Returns true if no error.

Throws

IOException
If the method could not read from pathname or write to os. Common reasons for failure include the following:

See Also

osSafeSpec

 

  Home > Contents > Index >

FatWire JAVA Reference
Copyright 2005 by FatWire Software
All rights reserved.