在vertx框架中,使用ResourcesUtil工具类读取json文件时,在本地启动时读取正常,但是部署到linux服务器上之后,会产生读取不到文件的异常,解决方法:
Vertx vertx = vertxContext.owner();
FileSystem fileSystem = vertx.fileSystem();
fileSystem.readFile("json/"+fileName+".json", res -> {
if (res.succeeded()) {
Buffer result = res.result();
String s = new String(result.getBytes(), StandardCharsets.UTF_8);
asyncResultHandler.handle(succeededFuture(ResponseModel.respond200WithApplicationJson(s)));
} else {
logErrorAndResponse(false, res.cause(), asyncResultHandler);
asyncResultHandler.handle(succeededFuture(ResponseModel.respond404WithTextPlain("服务器未找到请求文件...")));
}
});
使用vertx自带的FileSystem可以解决这个问题。