reader = new Scanner(Paths.get(userDirectory + "/src/file.txt"));
my txt file is on src and program runs normally in IDE but jar file can't read my txt file how can i solve this problem.
reader = new Scanner(Paths.get(userDirectory + "/src/file.txt"));
my txt file is on src and program runs normally in IDE but jar file can't read my txt file how can i solve this problem.
I didn't get same problem, but I don't know What are you using for "userDirectory".
public class Main {
public static void main(String[] args) throws IOException {
String userDirectory = "/home/ubuntu/Desktop/Personal/testjarcreate";
Scanner reader = new Scanner(Paths.get(userDirectory + "/src/file.txt"));
System.out.println(reader.next());
}
} The content are "test,test" in file.txt's. When it build with this main, I get "test,test" result on terminal.