java.io.FileNotFoundException: Resource not found: /credentials.json on Java QuickStart for Classroom API

喜夏-厌秋 提交于 2021-01-29 06:36:43

问题


I have implemented the Java QuickStart for the Classroom API and am getting an error message "java.io.FileNotFoundException: Resource not found: /credentials.json" at run-time. I copied my credentials.json file to the Project res directory, but continue to get this error. Any suggestions?


回答1:


I tried it in a different way than I found on other websites, and it worked for me.

replace below code:

InputStream in = GoogleSheetAPIHandler.class.getClass().getResourceAsStream(CREDENTIALS_FILE_PATH);

With this code:

InputStream in = new FileInputStream(CREDENTIALS_FILE_PATH);



回答2:


You need to import credential.json file into the src/main/resources folder in eclipse. You may be included in the project folder. But you need to import it into eclipse.

  • locate your credentials.json file in the folder.
  • click and drag it
  • drop it in src/main/resource and click ok.
  • After importing into eclipse it should show like the below image.



来源:https://stackoverflow.com/questions/59292883/java-io-filenotfoundexception-resource-not-found-credentials-json-on-java-qui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!