Java reads INI file key-value pairs through the properties class

Source: Internet
Author: User
Tags new set object object

/*
The properties class uses system's Getproerties to return systems properties to pass a System.out
The use of this class is to read an INI configuration file information key = value
See Docs in concrete usage
*/

Import java.util.*;
Import java.io.*; FileInputStream in this bag.
Class Proptest
{
public static void Main (String []args)
{
/*properties p=system.getproperties ();
P.list (System.out); Output Java Run-time Systems Information System Property JVM
*/

Properties P=new properties (); New A Properties Object
Try
{
P.load (New FileInputStream ("Info.ini"));/load a file input stream
}
catch (Exception e)
{
E.printstacktrace ();
}
Enumeration Em=p.propertynames (); 1.0-1.1java the new set frame before it came out of the enumeration
while (Em.hasmoreelements ())//If more elements exist
{
String key= (String) em.nextelement ();//Return Object object we want to convert to string
String Value=p.getproperty (key); Get Value by key
System.out.println ("key=" +key+ "------" + "value=" +value);
}




}




}

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.