Searching...
Tuesday, July 15, 2014

Read file line by line

July 15, 2014


Normally, Java properties file is used to store project configuration data or settings. In this tutorial, we will show you how to read and write to/from a properties file.


ReadFileLineByLine

package java9r.blogspot.com;

import java.io.IOException;
import java.util.Properties;

public class ReadFileLineByLine {

public static void main(String[] args) {
Properties configFile = new Properties();
try {
configFile.load(ReadFileLineByLine.class.getClassLoader().getResourceAsStream("config.properties"));
String name = configFile.getProperty("name");
String age = configFile.getProperty("age");
System.out.println(name);
System.out.println(age);
} catch (IOException e) {

e.printStackTrace();
}
}

}

config.properties

 #userInfo
age=22
name=ravi
city=hyderabad

Output 

0 comments:

Post a Comment

ads2