【问题标题】:AWS: I deployed my microservice on AWS and it's working fine but the service class is unable to read data from the fileAWS:我在 AWS 上部署了我的微服务,它工作正常,但服务类无法从文件中读取数据
【发布时间】:2021-10-07 06:24:12
【问题描述】:

我刚刚部署了我的第一个微服务。我的微服务运行良好。所有路线都在工作。但是微服务内部的服务类不能正常工作。服务类未从 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;
}

}

服务类调用上述函数来获取所有人的详细信息。

以上代码在我的桌面上运行良好,我可以获取详细信息,但代码在 AWS 上无法运行。此外,我尝试删除 CSV 并手动输入值,它在 AWS 中工作。所以我 99% 确定读取 CSV 文件时存在问题。

有没有办法解决这个问题?

【问题讨论】:

    标签: amazon-ec2 amazon-ecr


    【解决方案1】:

    如果文件的路径上一级目录,则改为

    String file = ".\\src\\main\\resources\\pensioners.csv";
    

    试试,

    String file = "..\src\main\resources\pensioners.csv";
    

    我假设 AWS 服务器是 ubuntu 而你的本地是 windows OS。

    【讨论】:

      猜你喜欢
      • 2020-11-08
      • 2018-06-14
      • 1970-01-01
      • 1970-01-01
      • 2018-05-12
      • 1970-01-01
      • 2013-09-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多