Java IO stream

Source: Internet
Author: User

The API object that is able to read the sequence of bytes is the input stream (InputStream), which is the output stream (OutputStream) that can be written into the sequence of bytes. Bytes are the stored form of computer data, and any data can be read and written using a byte stream.

Read source and write target can be file, memory, network, database and file.

InputStream and OutputStream two abstract classes form the framework foundation of the read/write IO system.

Although the byte stream can manipulate any form of data, it is not very convenient for characters that occupy multiple bytes, so there are two abstract classes of reader and writer that are specifically provided for character streams in Java.

Classification:

Io stream by operand: byte stream and character stream

By direction of flow: input stream and output stream

System diagram of the main stream: each input stream has a corresponding output stream

After the abstract class Input/outputstream Readerwriter followed by the specific implementation subclass

Character Stream

Character stream is mainly for the processing of text content is very convenient to read and write, according to the character input and output and byte stream operation is not different, but the read and write operation unit is no longer a byte.

Get information about a file

It is known that there are two files under the current directory and can read its information using the API of the file object.

Query out file size, name, absolute path, parent directory, last modified time, whether to hide file

Warning: Mysterious hidden movies and selfies in the xxx disk are the fruit dew in front of the program.

Take a look at some of the common methods of file objects :

Role

function signature

Practical Grade

Get file name

String GetName ()

*****

Whether the disk file exists

Boolean exists ()

*****

Get the disk absolute address of the file

String GetAbsolutePath ()

*****

List of files under the column-fetching folder

With filters

There is a file name filter

File must be a folder to use

File[] Listfiles ()

File[] Listfiles (filefilter filter)

File[] Listfiles (filenamefilter filter)

*****

Create a folder

Boolean mkdir ()

*****

Create a file

Specify a file in the directory where the specified prefix and suffix are created

Boolean CreateNewFile ()

Createtempfile (string prefix, string suffix, File directory)

*****

Get Parent Directory

String getParent ()//upper file path

File Getparentfile ()//top-level files

*****

Whether to hide

Boolean Ishidden ()

*****

deleting files

Boolean Delete ()

*****

There are other ways to do this: such as determining whether the "executable method", "readable", "writable", and so on permissions files, more see the JDKAPI documentation.

Java IO stream

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.