Java I/O fundamentals

Source: Internet
Author: User

First, the file class

The file class is an abstract representation of the path names of files and directories. File is used only as a surface for a file or directory and cannot be modified for the contents of a document.

Common methods in the file class:

    • When the user accesses, operates the file or the directory, usually has the readable, the writable, the executable three kinds of permissions, may through the file class CanWrite (), CanRead (), CanExecute () judgment.
    • CreateNewFile () When a file with that name does not already exist, create a new file that is named after the abstract path name.
    • Exists () determines whether the file exists.
    • Delete () deletes the file or directory.
    • GetName () Gets the file or directory name.
    • Isdirectory () is a directory.
    • mkdir () Creating a directory
    • Mkdirs () Creates a directory that contains a directory that does not exist at the parent level.
    • Renameto () renames a file or directory.
    • List () returns an abstract array representing the files or directories in the directory.

Second, I/O

The I/O classes in the Java class Library are divided into two parts, input and output, and all classes related to the input should inherit from InputStream, and the output-related classes should inherit from OutputStream.

For text files read and write, in the form of a character stream. For binary storage of the file slices, video, word and so on in the form of byte stream read.

BYTE stream  

  InputStream

FileInputStream

Filterinputstream:datainputstream Bufferedinputstream

ObjectInputStream

OutputStream

FileOutputStream

Filteroutputstream:dataioutputstream Bufferedoutputstream

ObjectOutputStream

Character Stream

FileReader

BufferedReader

FileWriter

BufferedWriter

Conversion between a byte stream and a character stream (conversion stream)

 InputStreamReader:

Converts a byte array into a character reader in the program, which is also called decoding.

Outputstreamreader

Writes a string to a byte array into a text file, which is encoded.

Java I/O fundamentals

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.