【问题标题】:How To : Write a File with FileOutputStream?如何:使用 FileOutputStream 编写文件?
【发布时间】:2012-04-05 21:19:20
【问题描述】:

我正在做的是我正在为 BufferOutputStream 读取的文件和每一行数据将保存在 FileOutputStream 中,我想指定输出数据。

【问题讨论】:

    标签: java amazon-s3 amazon-web-services


    【解决方案1】:

    如果我理解正确,您想从 S3 下载文件并使用 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();
    

    【讨论】:

    • 是的。谢谢你太棒了!你太棒了!
    猜你喜欢
    • 2014-07-29
    • 1970-01-01
    • 2021-08-16
    • 1970-01-01
    • 2021-01-09
    • 2014-08-06
    • 2019-11-10
    • 1970-01-01
    • 2020-07-12
    相关资源
    最近更新 更多