Can I get properties defined in "gradle.properties" in JAVA STATEMENT?

I have defined a property in the file gradle.properties

as shown below:

user.password=mypassword

      

Can I use it as a variable value in my java statement?

+3


source to share


2 answers


Yes you can, however this is not a good idea or good practice. The file gradle.properties

is for saving gradle properties eg. JVM args used at build time.

If you need to store the user / pass pair in a properties file, it should be placed under src/main/resources

or other appropriate folder and separated from gradle.properties

.



Side note: Not sure if storing a properties file in a mobile app is generally safe.

+7


source


You will need to read the properties file and retrieve the property first.

Properties prop = new Properties();
InputStream input = null;

try {

    input = new FileInputStream("gradle.properties");

    // load a properties file
    prop.load(input);

    // get the property value and print it out
    System.out.println(prop.getProperty("user.password"));
} catch (IOException ex) {
    ex.printStackTrace();
}

      



You can find a detailed tutorial here

+6


source







All Articles