簡體   English   中英

為什么在此文件上運行 readAllBytes 時會收到 NoSuchFileException

[英]Why am I getting a NoSuchFileException when running readAllBytes on this file

我正在嘗試制作一個使用 OpenAPLR 的簡單 android 應用程序

http://doc.openalpr.com/cloud_api.html

所以我復制了Java部分下關於如何發出REST api請求的代碼,並將其全部放入按鈕的onClick方法中,並拍攝了車牌照片並將其保存為license_plate.jpg在該位置

應用程序/res/drawable/license_plate.jpg

但是每當我運行應用程序時,我總是收到指向這些行的錯誤

Path path = Paths.get("drawable/license_plate.jpg");
byte[] data = Files.readAllBytes(path);

java.nio.file.NoSuchFileException: drawable/license_plate.jpg

我應該在哪里保存這個圖像,以便我可以在應用程序中使用它? 當我不只是使用我已經預加載的單個圖片時,我應該在哪里保存用於未來應用程序的圖像?

你給錯了路徑。 您只能在設備中保存圖片,然后給出圖片文件夾路徑,例如:

Path path = Paths.get("/storage/projects/alpr/samples/testing/car1.jpg");
byte[] data = Files.readAllBytes(path);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM