Java Basic notes (vii)

Source: Internet
Author: User

Properties:
A subclass of Hashtable, which belongs to the collection class. Store property The key value pair of the heart, the key and the value by default is a string is a collection class that can be used in conjunction with a stream
Properties Pro = new properties ();
Pro.setproperty ("name", "Tom");
Pro.setproperty ("Age", "19");
Pro.setproperty ("Sex", "boy");
System.out.println (PRO);

    // 获得所有属性名的集合    Set<String> names = pro.stringPropertyNames();    Iterator<String> it = names.iterator();    while (it.hasNext()) {        String key = it.next();        String value = pro.getProperty(key);        System.out.println(key + "----" + value);    }

Used in conjunction with file streams:
Load the. properties file through the Properties class and read the information
1 Stream 2 Create a Properties object, load a property file 3 read the information by means of the attributes object
Write Properties File
static void WriteProperties (file file, Map

Data flow: specifically used to write basic types of data, read and write the order of strict correspondence
DataInputStream (InputStream)
ReadInt ()
Readdouble ()
readUTF ()

DataOutputStream (OutputStream)
Writeint ()
Writedouble ()
writeUTF ()
Flush ()

Create a data flow
DataOutputStream OS = new DataOutputStream (New FileOutputStream (
"Src/data.txt"));
Os.writedouble (12.2);
Os.writeint (10);
Os.writeutf ("Study hard");
Os.flush ();

    // 读    DataInputStream is = new DataInputStream(new FileInputStream(            "src/data.txt"));    System.out.println(is.readDouble());    System.out.println(is.readInt());    System.out.println(is.readUTF());

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java Basic notes (vii)

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.