How To : Write a File with FileOutputStream?

By : John V
Source: Stackoverflow.com
Question!

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.

By : John V


Answers
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();


This video can help you solving your question :)
By: admin