John V
John V

Reputation: 63

How To : Write a File with FileOutputStream?

What I'm doing is that the file and each line of data I'm reading for BufferOutputStream will be saved in a FileOutputStream and I want to specify the output data.

Upvotes: 0

Views: 2917

Answers (1)

shashankaholic
shashankaholic

Reputation: 4122

If i have understood correct, you want to download the file from S3 and write to your local directory using BufferedOutputStream .

    S3Object object = s3.getObject(new GetObjectRequest(bucketName, key));
    InputStream is = object.getObjectContent();



 // Creating file
        File file= new File(localFilePath);
        FileOutputStream fos = new FileOutputStream(file);
        BufferedOutputStream bos= new BufferedOutputStream(fos);

    int read = -1;

    while ((read = is.read()) != -1) {
        bos.write(read);
    }

    bos.flush();
    bos.close();
    is.close();

Upvotes: 3

Related Questions