Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.util.Properties$LineReader.readLine

I need to read a config file I get this error while running the following code:

java.util.Properties$LineReader.readLine

The file config.cfg is present and has r/w permissions.

import java.util.*;
import java.util.Properties;

public class Config   
{
 Properties configFile;
 public Config()
 {
configFile = new java.util.Properties();
try {           
  configFile.load(this.getClass().getClassLoader().
  getResourceAsStream("config.cfg"));           
}catch(Exception eta){
     eta.printStackTrace();
}
}

public String getProperty(String key)
{

 String value = this.configFile.getProperty(key);       
 return value;

 }

}

EDIT - Full Error

 [java] java.lang.NullPointerException
 [java]     at java.util.Properties$LineReader.readLine(Properties.java:418)
 [java]     at java.util.Properties.load0(Properties.java:337)
 [java]     at java.util.Properties.load(Properties.java:325)
 [java]     at Config.<init>(Unknown Source)
 [java]     at ClosureBuilder.<clinit>(Unknown Source)

EDIT - Directory Structure

src

-> config.java

-> config.cfg

like image 700
Umesh Moghariya Avatar asked May 23 '12 05:05

Umesh Moghariya


1 Answers

You have to put your config.cfg in the same folder where your .class file lies.

like image 151
helpermethod Avatar answered Oct 07 '22 13:10

helpermethod