How to use an INI file JAVA


user.ini

DBuser=rampukar
DBpassword=mos
DBlocation=db_java


readIni.java

import java.util.*;
import java.io.*;

class readIni {
  public static void main(String args[]) {
    readIni ini = new readIni();
    ini.doit();
    }

  public void doit() {
    try{
      Properties p = new Properties();
      p.load(new FileInputStream("user.ini"));
      System.out.println("user = " + p.getProperty("DBuser"));
      System.out.println("password = " + p.getProperty("DBpassword"));
      System.out.println("location = " + p.getProperty("DBlocation"));
      p.list(System.out);
      }
    catch (Exception e) {
      System.out.println(e);
      }
    }

}

Folder Structure :

Output


Share on Google Plus

About Ram Pukar

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment

0 comments:

Post a Comment