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?
propertiesFile
. Use it... – Fildor