Java file path in Linux

后端 未结 3 591
-上瘾入骨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:12

    Looks like you are missing a leading slash. Perhaps try:

    Scanner s = new Scanner(new File("/home/me/java/ex.txt"));
    

    (as to where it looks for files by default, it is where the JVM is run from for relative paths like the one you have in your question)

提交回复
热议问题