-2

I have a project organized this:

-LIBRERIA CLIENT/
   -SRC/
     -CONNECTION/
      CONNECTIONdB.JAVA
      CONFIG.PROPERTIES

In CONNECETIONDB I have this code to read the CONFIG.PROPERTIES file:

public static void connect() throws RemoteException
{
        //read file config.properties:
        String dbHost="",dbUser="",dbPassword="";
        Properties prop=new Properties();
        try
        {
            //load il file:
            prop.load(new FileInputStream("src/Connectionconfig.properties"));
            //read the property of file
            dbHost=prop.getProperty("host");
            dbUser=prop.getProperty("user");
            dbPassword=prop.getProperty("password");
        }catch(FileNotFoundException fe){
            System.out.println("File not found");
        }catch(IOException ex){
            System.out.println("Error reading configuration file");
        }

But I have this error:

     FILE NOT FOUND 

Could someone tell me where am I going wrong?

mmmmmm
  • 32,227
  • 27
  • 88
  • 117

2 Answers2

1

That's easy: your code is executed in different folders from your project_root. Moreover: src/Connectionconfig.properties does not exists: it should be SRC/CONNECTION/CONFIG.PROPERTIES, if you execute project from project_root.
Also look at this to get current working directory: Getting the Current Working Directory in Java

Community
  • 1
  • 1
popfalushi
  • 1,332
  • 9
  • 15
0

Your code read Connectionconfig.properties file under src but according to your project structure only CONFIG.PROPERTIES exists under SRC/CONNECTION. Change to

  prop.load(new FileInputStream("SRC/CONNECTION/CONFIG.PROPERTIES"));

instead of

  prop.load(new FileInputStream("src/Connectionconfig.properties"));
swemon
  • 5,840
  • 4
  • 32
  • 54