If you want to use relative path and you has used SpringBoot,you should do:
URL resource=this.getClass().getClassLoader().getResource("test.txt"); File file = new File(resource.getPath());