Java file path in Linux

后端 未结 3 573
-上瘾入骨i
-上瘾入骨i 2021-01-04 06:24

I have a rather silly question, but I haven\'t been able to find a solution for this:

When I try and read a file I get a \"file not found error\" is runtime. It

3条回答
  •  抹茶落季
    2021-01-04 07:15

    I think Todd is correct, but I think there's one other thing you should consider. You can reliably get the home directory from the JVM at runtime, and then you can create files objects relative to that location. It's not that much more trouble, and it's something you'll appreciate if you ever move to another computer or operating system.

    File homedir = new File(System.getProperty("user.home"));
    File fileToRead = new File(homedir, "java/ex.txt");
    

提交回复
热议问题