'FileInputStream FileNotFoundException but file definitely exists

I am encountering a weird FileNotFoundException with FileInputStream while working in Android Studio. Using this post, I ran some checks, but still cannot find the issue.

This is my code:

package com.mypackage;

import java.io.FileInputStream;
import java.sql.*;
import java.util.*;
import java.util.logging.Logger;
import java.io.File;

public class DatabaseDriver {

    public DatabaseDriver(){
        Properties properties = new Properties();

        // get credentials from application.properties file
        FileInputStream in = new FileInputStream("application.properties");
        properties.load(in);

        String url = properties.getProperty("url");
        String user = properties.getProperty("user");
        String password = properties.getProperty("password");
    }

} 

With some of the tips from the above post, I ran the following code in a debugging attempt:

public class DatabaseDriver {
    public DatabaseDriver(){

        File file = new File("application.properties");
        System.out.println(new File(".").getAbsolutePath());
        System.out.println(new File("application.properties").getAbsolutePath());
        System.out.println(file.exists());
        System.out.println(file.canRead());
        System.out.println(file.isDirectory());
    }
}

And the output when I create a DatabaseDriver instance in a main:

C:\Users\erin\AndroidStudioProjects\RecCenter\.
C:\Users\erin\AndroidStudioProjects\RecCenter\application.properties
true
true
false

That all seems fine, so I'm a little lost.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source