AWS:我在 AWS 上部署了我的微服务,它工作正常,但服务 class 无法从文件中读取数据
AWS: I deployed my microservice on AWS and it's working fine but the service class is unable to read data from the file
我刚刚部署了我的第一个微服务。我的微服务运行良好。所有路线都在运作。但是微服务内部的服务class没有正常运行。服务 class 未从 CSV 文件中读取数据。
下面是我用来从 CSV 文件读取数据的代码。
public class ReadCsvUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(ReadCsvUtil.class);
public List<String[]> readData() throws IOException {
String file = ".\src\main\resources\pensioners.csv";
List<String[]> content = new ArrayList<>();
try(BufferedReader br = new BufferedReader(new FileReader(file))) {
String line = "";
while ((line = br.readLine()) != null) {
content.add(line.split(","));
}
} catch (FileNotFoundException e) {
LOGGER.debug(e.getMessage());
}
return content;
}
}
服务class调用上述函数获取所有人的详细信息。
以上代码在我的桌面上运行良好,我可以获取详细信息,但代码在 AWS 上无法运行。此外,我尝试删除 CSV 并手动输入值,它在 AWS 中工作。所以我 99% 确定读取 CSV 文件时有问题。
我有办法解决这个问题吗?
如果文件路径向上一个目录,而不是
String file = ".\src\main\resources\pensioners.csv";
尝试,
String file = "..\src\main\resources\pensioners.csv";
我假设 AWS 服务器是 ubuntu 而您的本地服务器是 windows OS.
我刚刚部署了我的第一个微服务。我的微服务运行良好。所有路线都在运作。但是微服务内部的服务class没有正常运行。服务 class 未从 CSV 文件中读取数据。
下面是我用来从 CSV 文件读取数据的代码。
public class ReadCsvUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(ReadCsvUtil.class);
public List<String[]> readData() throws IOException {
String file = ".\src\main\resources\pensioners.csv";
List<String[]> content = new ArrayList<>();
try(BufferedReader br = new BufferedReader(new FileReader(file))) {
String line = "";
while ((line = br.readLine()) != null) {
content.add(line.split(","));
}
} catch (FileNotFoundException e) {
LOGGER.debug(e.getMessage());
}
return content;
}
}
服务class调用上述函数获取所有人的详细信息。
以上代码在我的桌面上运行良好,我可以获取详细信息,但代码在 AWS 上无法运行。此外,我尝试删除 CSV 并手动输入值,它在 AWS 中工作。所以我 99% 确定读取 CSV 文件时有问题。
我有办法解决这个问题吗?
如果文件路径向上一个目录,而不是
String file = ".\src\main\resources\pensioners.csv";
尝试,
String file = "..\src\main\resources\pensioners.csv";
我假设 AWS 服务器是 ubuntu 而您的本地服务器是 windows OS.