Search This Blog

Breaking

Saturday, 26 March 2022

Azure -> Java -> How to read a file without downloading present inside a azure container?

 If you want to read a file from a Azure container folder without downloading to it, you can easily do it by using azure API's. The correct way to download a file from azure container folder is to first ensure that the container is present or not.

So if you want to check that the container is available or not, please check this post











Once you have ensured that the container is present, you can use below method:

  public static void readFile(String containerName, String fileName) throws IOException {
        BlobServiceClient blobServiceClient = createBlobServiceClient();
        BlobContainerClient containerClient =blobServiceClient.getBlobContainerClient(containerName);
        BlobClient blob = containerClient.getBlobClient(fileName);
        BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(blob.openInputStream()));
        String line;
        while ((line = bufferedreader.readLine()) != null)
        {
            System.out.println(line);

        }

    }

Here we are reading the file after converting it into a stream.

No comments:

Post a Comment