0

As the title says, I am getting the java.nio.file.NoSuchFileException when trying to use the downloadToFile method. I read some doc and it says that the way this method works is that if the file exists, it will throw a FileAlradyExistsException which happened to me when I manually created the file. But I find it weird that when the file doesn't exist, it throws the opposite...

        String localPath = "/Download/"; // this is the path within my server
        BlobClient blobClient;
        for (int i = 0; i < files.length; i++){
            blobClient = container.getBlobClient(files[i]);


            blobClient.downloadToFile(localPath + files[i]);
        }

        System.out.println("Done");
Kass224
  • 89
  • 11
  • https://stackoverflow.com/questions/2642919/checking-if-a-blob-exists-in-azure-storage is this helpful – zolty13 Sep 24 '21 at 19:26
  • Unfortunately not, this checks if the blob exists. In my case, I want to create the file in my specified folder. – Kass224 Sep 24 '21 at 19:28
  • What exactly is your problem? You want to download file or to upload it. In blob storage there is no folders at all. If you want to upload file why do you use download method – zolty13 Sep 24 '21 at 19:46
  • I am trying to download... – Kass224 Sep 24 '21 at 19:53
  • @zolty13 My precise expectation (even though it was already precise) : I want to take a blob on azure and make it a file in my server. – Kass224 Sep 24 '21 at 19:54
  • I tried this and many other docs, but nothing works... https://learn.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-java?tabs=bash#download-blobs – Kass224 Sep 24 '21 at 19:55
  • The file you want download does not exists on azure blob storage so you receive `java.nio.file.NoSuchFileException`. `FileAlradyExistsException` is thrown when file with such a name already exists at your local file system, in your case it is your server – zolty13 Sep 24 '21 at 20:04
  • then how do I check if the file exists? – Kass224 Sep 24 '21 at 20:09
  • I don't think that this is the problem, the blobClient.exists() returns true. – Kass224 Sep 24 '21 at 20:13
  • `Sep. 24, 2021 4:12:40 P.M. com.azure.core.util.logging.ClientLogger performLogging SEVERE: java.nio.file.NoSuchFileException: /Download/User_Manual/manual.pdf` – Kass224 Sep 24 '21 at 20:14
  • Does path for this new downloaded file exists? /Download/User_Manual – zolty13 Sep 24 '21 at 20:18
  • no, otherwise it would throw the `FileAlradyExistsException` – Kass224 Sep 24 '21 at 20:19
  • Please provide more code. Also with you tryings with File Exists method. – zolty13 Sep 24 '21 at 20:38
  • Forget it, I fixed it... – Kass224 Sep 24 '21 at 20:47
  • So please provide answer below. Good night – zolty13 Sep 24 '21 at 20:49
  • 1
    It still doesn't work ideally, I will provide it when I'm done! – Kass224 Sep 24 '21 at 21:09
  • 1
    You need to ensure that “User_Manual” folder exists inside your “Download” folder. SDK will not create this folder for you. – Gaurav Mantri Sep 25 '21 at 00:40

1 Answers1

0

As @Gaurav Mantri mentioned, the folder itself had to be present. So I had to build all the folders and now the files load perfectly.

Kass224
  • 89
  • 11