Get file from project folder java

后端 未结 9 642
庸人自扰
庸人自扰 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-24 07:14

    This sounds like the file is embedded within your application.

    You should be using getClass().getResource("/path/to/your/resource.txt"), which returns an URL or getClass().getResourceAsStream("/path/to/your/resource.txt");

    If it's not an embedded resource, then you need to know the relative path from your application's execution context to where your file exists

提交回复
热议问题