Get the filePath from Filename using Java

后端 未结 5 1018
日久生厌
日久生厌 2021-01-04 05:33

Is there a easy way to get the filePath provided I know the Filename?

5条回答
  •  没有蜡笔的小新
    2021-01-04 06:22

    Correct solution with "File" class to get the directory - the "path" of the file:

    String path = new File("C:\\Temp\\your directory\\yourfile.txt").getParent();
    

    which will return:

    path = "C:\\Temp\\your directory"
    

提交回复
热议问题