Java--io operation

Source: Internet
Author: User

Java's IO class operations mainly include the following categories

1, the use of the file class.

2, byte operation flow: OutputStream, InputStream

3, character operation Flow: Reader, Writer

4. Serialization of objects: Serializable

InputStream

The InputStream read stream has 3 methods, respectively

First: Abstract int read ()
Reads a single byte from this stream and returns it as an integer in the range from 0 to 255.

Reads one byte from the stream at a time and represents the byte as an integer type of 0 to 255. (for example, Chinese characters, which are split into two bytes and represented as an integer type, become two numbers)

Instance:

 public  class   Test { public  static  void   main (string[] args) {String        String  = "Test using" ;         byte  [] bs=string.getbytes ();        System.out.print (bs.length  + "" );  for  (int  i = 0; i < bs.length; i++         +"  new  String (BS) ); }}

Results: 8-78-30-54-44-54-71-45-61 test use

Second: int read (byte[] buffer)
Equivalent to read (buffer, 0, buffer.length).

Equal to read (buffer, 0, buffer.length)

Third: int read (byte[] buffer, int offset, int length)

Reads at more than length bytes from this stream and stores them in the byte array b starting at offset.

Reads the length of bytes from the stream and puts it into the B array starting at the offset position.

where the Read () method reads one byte at a time, the efficiency is very low. So it is best to use the following two methods.

Java--io operation

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.