Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 上载到Google云平台时无法读取CSV文件_Spring Boot_Csv_Google Cloud Platform_Filenotfoundexception - Fatal编程技术网

Spring boot 上载到Google云平台时无法读取CSV文件

Spring boot 上载到Google云平台时无法读取CSV文件,spring-boot,csv,google-cloud-platform,filenotfoundexception,Spring Boot,Csv,Google Cloud Platform,Filenotfoundexception,我的Spring Boot应用程序结构如下 在csvService.java类中,我试图读取test.csv文件。我可以在localhost上读取它,但是当我将它部署到谷歌云平台时,它无法读取文件,并给出FileNotFoundException 这是负责读取csv文件的代码行: CSVReader reader = new CSVReader(new InputStreamReader(newFileInputStream("test.csv"), "UTF8")); 文件结构与您部署它的

我的Spring Boot应用程序结构如下

csvService.java
类中,我试图读取
test.csv
文件。我可以在localhost上读取它,但是当我将它部署到谷歌云平台时,它无法读取文件,并给出FileNotFoundException

这是负责读取csv文件的代码行:

CSVReader reader = new CSVReader(new InputStreamReader(newFileInputStream("test.csv"), "UTF8"));

文件结构与您部署它的位置不同,
test.csv
文件可能没有打包到二进制文件中。因此,您将得到一个文件NotFoundException——该文件根本不在本地计算机上的位置

为您的项目指定/澄清的事项:

  • 在何处以及如何部署?是GKEGCE还是AppEngine?查找它们在部署jar文件时的行为
  • 为什么要在生产环境中部署
    test.csv
    文件?当然,您希望动态获取该csv文件,而不是静态获取(除非它有特定的含义)-如果确实要获取该csv文件,请将其放入参考资料文件夹中,并将其视为静态获取。您需要稍微更改文件读取代码

  • 实际上,问题在Docker文件中。正在创建映像,wsa仅使用jar。我需要在Docker文件中添加以下行。
    复制--from=builder/app/test.csv/test.csv

    是否有人可以帮助您运行
    ls
    时是否看到列出的test.csv?是的,当我在本地计算机上运行ls时,我可以看到csv文件当然,您将在本地计算机上看到它-文件没有传播到您的分发方式中。如果你正在制作一个jar文件,它不会打包在里面。如果你想把它放在那里,你必须把它变成一种资源。否则,可以动态访问它,例如从Google云存储访问。将其放入resources文件夹中,并尝试使用此CSVReader reader=new CSVReader(new InputStreamReader(newFileInputStream(“src/main/resources/config/test.csv”),“UTF8”);我在resources文件夹中添加了csv文件,并尝试像这样读取CSVReader reader=newCSVReader(newInputStreamReader(newFileInputStream(“src/main/resources/config/test.csv”),“UTF8”);这是正确的方法吗?或者必须给Google Kubernetes Engine一些其他的路径。你不能使用绝对路径。改用。