Four sets of reading and writing programs

Source: Internet
Author: User

First set: Byte stream read Write scheme

FileInputStream: Byte stream read text file

FileOutputStream: Byte stream write to hard disk

Second set: Character Stream read Write scheme

FileReader: Character Stream reads text

FileWriter: Character Stream writes text

BufferedReader: Custom cache size, read text 8,192 Char

BufferedWriter: Writing text

Generally used in combination with FileReader and filewriter

Fourth set: can read binary (img image, etc.)

DataInputStream: Loading the local img into memory

DataOutputStream:: Writes the In-memory binary data to a file on the hard disk.

Serialization and deserialization:

//Serialization of List<dog> list=New arraylist<dog>(); List.add (New Dog ("Peas",15)); List.add (New Dog ("Peas 2",15)); F ObjectOutputStream oos=NewObjectOutputStream (FOS); Oos.writeobject (list); Fos.close (); Oos.close (); System.Out.println ("Serialization succeeds!"); Deserialization fileinputstream fis=new FileInputStream ( "save.bin "); ObjectInputStream ois=new ObjectInputStream (FIS); List<dog> list= (List<dog>for (Dog dog:list) {system..println (Dog.getname ());} Note: 0102public String msg               

Four sets of reading and writing programs

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.