How To : Write a File with FileOutputStream?

Go To StackoverFlow.com

0

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.

2012-04-05 21:19
by John V
I don't understand... - dacwe 2012-04-06 05:58


3

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();
2012-04-06 11:54
by shashankaholic
YES. Thank you soooooo mcuch! You're awesome - John V 2012-04-06 16:24
Ads