0

I have Created a Property file and stored in root Folder. (java Web project, servlet)

Code:

Properties prop = new Properties();        
        try {
            prop.setProperty("EPU", "A1,A2,A3,A4,A8,A9,B1,B2,B3,B8,B9");
            //save properties to project root folder
            prop.store(new FileOutputStream("dbsc.properties"), null);

        } catch (IOException ex) {
        }

and the property file created successfully in the below path

Project ->Project Name ->dbsc.properties

then i want to read (load) this property file, code below

prop.load(new FileInputStream("dbsc.properties"));

when i executed received a FileNotFoundException

 java.io.FileNotFoundException: kindcode.properties (The system cannot find the file specified)

My Question:

Is it correct procedure and path to save the property file?

how can i load the property file?

Prabu
  • 3,550
  • 9
  • 44
  • 85

1 Answers1

0

You should not use root directory of project to store or create property files.You should use resources directory(classpath) and correct way to load those is :

props.load(getClass().getResourceAsStream("dbsc.properties"));
Ankit Tripathi
  • 405
  • 4
  • 13