How do I get a file's directory using the File object?

后端 未结 9 2079
半阙折子戏
半阙折子戏 2020-12-08 18:02

Consider the code:

File file = new File(\"c:\\\\temp\\\\java\\\\testfile\");

testfile is a file, and it may or may not exist.

9条回答
  •  忘掉有多难
    2020-12-08 18:28

    I found this more useful for getting the absolute file location.

    File file = new File("\\TestHello\\test.txt");
    System.out.println(file.getAbsoluteFile());
    

提交回复
热议问题