gpt4 book ai didi

java - Android 上的“filenotfound”异常

转载 作者:行者123 更新时间:2023-11-30 02:14:14 27 4
gpt4 key购买 nike

即使路径存在,我仍然收到找不到文件的异常。该路径取 self 最初创建文件的位置,因此我假设该路径是正确的。错误发生在下面的 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

关于java - Android 上的“filenotfound”异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29635032/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com