1

How to Read 100 lines at a time of a CSV file from s3 using aws sdk. In below code i am reading single line at a time.

S3Object o  = s3Client.getObject("temp", "file_name");
            InputStreamReader inputStreamReader = new InputStreamReader(o.getObjectContent());
            BufferedReader reader = new BufferedReader(inputStreamReader);
            String s = null;
            while ((s = reader.readLine()) != null)
            {
                System.out.println(s);
                //your business logic here
            }
            inputStreamReader.close();

Is there any way to read 100 or 1000 line at a time.

1 Answers1

2

For file with small size, Amazon provides getObjectAsString. You can try as

String objAsString  = s3Client.getObjectAsString("temp", "file_name");

what it does is

Retrieves and decodes the contents of an S3 object to a String.

You can also use lines() and collect to a List<String> after getting BufferedReader reader

reader.lines().collect(Collectors.toList());

You can refer to some other ways here

Tuan Hoang
  • 586
  • 1
  • 7
  • 14