I'd like my program to find location from which it was run, i.e. program uses txt file and I'd like it to look for this txt file in the same directory as jar file. I am aware of the existence of Path class, but I don't have a clue how to use it in this situation. For the time being I'm using a fixed path, but it's not good enough.
package readsqlfromfile;
import java.io.*;
import java.util.Scanner;
public class ReadSqlFromFile {
static File file = new File ("C:\\sql\\sql.txt");
public static void main(String[] args) throws FileNotFoundException {
Scanner input =new Scanner(file);
String linia = new String ("");
while (input.hasNextLine()) {
linia = input.nextLine();
if (linia.length()>4) {
if (linia.substring(0, 4).equals("sql:")) {
//some database logic here
}
}
}
}
}