Get file from project folder java

后端 未结 9 644
庸人自扰
庸人自扰 2020-12-24 06:56

I want to get File from project folder by using \"File class\" , How I can Do that ?

File file=new File(\"x1.txt\");
9条回答
  •  北海茫月
    2020-12-24 07:23

    Just did a quick google search and found that

    System.getProperty("user.dir");
    

    returns the current working directory as String. So to get a File out of this, just use

    File projectDir = new File(System.getProperty("user.dir"));
    

提交回复
热议问题