rmaik
rmaik

Reputation: 1086

.exists() method always returns false

In the below code, I am checking if a file exists in a specific path using the method isExist(). The problem is this method always returns false no matter the file exists or not.

Kindly please have a look at the code posted below, and let me know what I am missing. Code:

    if (isExist(SYS_CONFIG_PATH, SYS_CONFIG_FILE)) {
                System.out.println("@SystemConfig->getInstance(): System Configuration File " + SYS_CONFIG_FILE + " exists.");
                return new File(SYS_CONFIG_PATH + "\\" + SYS_CONFIG_FILE);
            }else {
                System.out.println("@SystemConfig->getInstance(): System Configuration File " + SYS_CONFIG_FILE + " is not existing, will be created.");
                return buildPathAt(SYS_CONFIG_PATH);
     ....
     ....

     private static boolean isExist(String path1, String path2) {
    // TODO Auto-generated method stub
    String path = path1 + path2;
    return new File(path.trim()).exists();
}

Upvotes: -1

Views: 217

Answers (1)

Ya Wang
Ya Wang

Reputation: 1808

It simply looks like SYS_CONFIG_PATH, SYS_CONFIG_FILE are over lapping into something like...

C:/user/temp + C:/user/temp/myfile.txt = C:/user/tempC:/user/temp/myfile.text

System.out these SYS_CONFIG_PATH, SYS_CONFIG_FILE

You might be able to see the problem there.

Upvotes: 2

Related Questions