我試圖找到一個包含 PDF 的檔案夾。當后端和前端不是 Jar 檔案時,一切正常。我的問題是你如何定位檔案,如果它在一個 JAR 中,我收到的只是一個找不到檔案的例外
嘗試將檔案添加到我的資源檔案夾中,但仍然沒有。我錯過了什么?

uj5u.com熱心網友回復:
這可以通過多種方式完成,這里有幾個:
// get the resources as a URL
URL resource = getClass().getClassLoader().getResource(
"static/test/TrainingDocuments/SuperUser/2/PartnerInformation/PartnerInformation.pdf");
// get the resource as a classPathResource
ClassPathResource classPathResource = new ClassPathResource(
"static/test/TrainingDocuments/SuperUser/2/PartnerInformation/PartnerInformation.pdf");
// get the resource directly as a stream
InputStream resourceAsStream = getClass().getClassLoader()
.getResourceAsStream("static/test/TrainingDocuments/SuperUser/2/PartnerInformation/PartnerInformation.pdf");
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/458921.html
上一篇:為什么查看檔案時出現值錯誤?
下一篇:替換文本檔案Python中的值
