How to write path to go one level up and then down into another directory

前端 未结 2 1220
醉话见心
醉话见心 2021-02-12 22:20

I\'m trying to open a file in a Java program (say Program.java) using relative path.

I have two directories as follows:

Project         


        
相关标签:
2条回答
  • 2021-02-12 22:30
    String path="firstpath" +File.separator +".." +File.separator +"secondpath";
    
    0 讨论(0)
  • 2021-02-12 22:32

    From what you are saying, you should set path to:

    ../Business/Scenarios/SC01.txt
    

    ../ to go up one level then the rest is the relative path against ProjectWork

    In Java file when you use a relative path without another argument, the file is matched against the System property user.dir which matches the working directory.

    0 讨论(0)
提交回复
热议问题