簡體   English   中英

Android上的“ filenotfound”異常

[英]'filenotfound' exception on Android

即使路徑存在,我仍然不斷發現文件未找到異常。 該路徑是從我最初創建文件時獲取的,因此我認為該路徑是正確的。 錯誤發生在下面的FileInputStream標記處。

這是錯誤:W / System.err? java.io.FileNotFoundException:/file:/storage/emulated/0/footyman/img_1429035461315.jpg:打開失敗:ENOENT(沒有這樣的文件或目錄)

     public static void addProfilePic(final Uri path,final String imgName) {

        new AsyncTask<Void, Void, String>() {
            @Override
            protected String doInBackground(Void... par) {
                String done;

                try {
                    // Retrieve storage account from connection-string.
                    CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);

                    // Create the blob client.
                    CloudBlobClient blobClient = storageAccount.createCloudBlobClient();

                    // Retrieve reference to a previously created container.
                    CloudBlobContainer container = blobClient.getContainerReference("profilepics");

                    // Define the path to a local file.
                    final String filePath = path.toString();
                    Log.i("filepath", filePath);

                    // Create or overwrite the "myimage.jpg" blob with contents from a local file.
                    CloudBlockBlob blob = container.getBlockBlobReference(imgName);
                    File source = new File(path.toString()); // error here
                    blob.upload(new FileInputStream(source.toURI().getPath()), source.length());
                    done = "true";
                }
                catch (Exception e) {
                    // Output the stack trace.
                    done = "false";
                    e.printStackTrace();
                }
                return done;
            }

            protected void onPostExecute(String done) {
                if (done.equals("true")) {
                    Log.i("add pic", "success");
                } else {
                    Log.i("add pic", "failed");

                }
            }
        }.execute();
    }
}

/file:/storage/emulated/0/footyman/img_1429035461315.jpg刪除“ / file:”,以便僅使用/storage/emulated/0/footyman/img_1429035461315.jpg

您的URI格式不正確,應如下所示:

文件:///storage/emulated/0/footyman/img_1429035461315.jpg

暫無
暫無

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

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