我正在尝试使用spring mvc定义相对路径而不是绝对路径。有谁知道怎么做?
private static final String FILE_PATH = "/Users/andyhe/Documents/workspace-sts-3.8.3.RELEASE/gti660/Equipe5/src/iTunesClone - Lab 2/iTunesClone/WebContent/resources/download/json/recherche.json";
private File getFileP() throws FileNotFoundException {
File file = new File(FILE_PATH);
if (!file.exists()){
throw new FileNotFoundException("file with path: " + FILE_PATH + " was not found.");
}
return file;
}
答案 0 :(得分:2)
它与Spring无关。
创建文件夹src/main/resources
并将文件保存在那里。
然后通过以下方式找到它们:
URL resource = YourClass.class.getClassLoader().getResource("recherche.json")
File file = new File(resource.getFile());
从那里继续..