How to specify filepath in java?

Yatendra picture Yatendra · Nov 7, 2009 · Viewed 108.3k times · Source

I have created a java application for "Debian Linux." Now I want that that application reads a file placed in the directory where the jar file of that application is specified. So what to specify at the argument of the File Object?

File fileToBeReaded = new File(...);

What to specify as argument for the above statement to specify relative filepath representing the path where the jar file of the application has been placed?

Answer

Carl Smotricz picture Carl Smotricz · Nov 7, 2009

If you know the name of the file, of course it's simply

new File("./myFileName")

If you don't know the name, you can use the File object's list() method to get a list of files in the current directory, and then pick the one you want.