我正在加载如下资源文件
public static JSONArray readConfig(String fileName) throws IOException, JSONException{
ClassPathResource res = new ClassPathResource(fileName);
byte[] bdata = FileCopyUtils.copyToByteArray(res.getInputStream());
String json = new String(bdata, StandardCharsets.UTF_8);
JSONArray jarr = new JSONArray(json);
return jarr;
};
我想知道是否有可能在资源/类路径中添加外部位置/文件,例如“ /something/something1/config.json”,以便可以通过与上述相同的代码读取。
谢谢...
答案 0 :(得分:0)
您可以在类路径中添加文件夹位置。
java -Dloader.path="/something/something1/" -jar your-app.jar
有关loader.path
文档,请参见link
如果要加载不在类路径中的资源,请使用FileSystemResource
而不是ClassPathResource
,这样它将在文件系统中加载该资源。