简体   繁体   中英

my program can read txt file whilerunning on intellij but when i create jar file it can't read

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM