2
votes

public static void main(String[] args) {

        for (String a : args) {
        System.out.println(a);
    }

public class CustomConfiguration {

public static void readConfig(String filename) { //read from config.properties file

try {
        String File = filename;
        System.out.println ("ConfigFile :" + File);
String result = "";
Properties properties = new Properties();
String propFileName = filename;
InputStream inputStream = new FileInputStream(propFileName);
    }

}

My question is how can i pass the "a" to the CustomConfiguration class?

1
So, what's your question?robertoia
@RobertoIzquierdo He actually put the question in the code comment lolz.ha9u63ar
You already have a parameter propertiesFile. Use it...Fildor

1 Answers

1
votes

As other users have pointed that out already - using propertiesFile property can make your application really flexible as you only need to change the propertiesFile content and your application will obtain the necessary information from it. For example, if you had the following in your properties file:

myFileName=C:/gherkins
typeOfMeat=Beef
typeOfRisk=Very High

you can extract the myFileName property and get the value `C:/gherkins' in your class wherever you want. In case you change the values in your properties file, your class doesn't have to do anything except getting the new information - easy. If you are unclear, follow this - http://crunchify.com/java-properties-file-how-to-read-config-properties-values-in-java/

Alternatively:

You can use String[] args in main method to pass the filename you are interested in. You can use that everywhere else. args[0] is always the path of the class file you are running and args[1], args[2], etc. will be the extra arguments supplied to the class application. In your case you want to extract the file name by doing String myFileName = args[1]; and use myFileName in other places.

p.s. in your code the filename path is C://... You sure this // is correct? you might wanted to put C:\\my_file_name escaping backslash? or just use one forward slash?