如何在响应良好的文件夹中存储响应图像?

问题描述 投票:0回答:1

我要求放心的API-

https://www.qrtag.net/api/qr_10.png?url=https://www.halodoc.com

并获得响应,响应和QR码图像,如何将其存储在文件夹中。

java api rest rest-assured
1个回答
0
投票

您可以使用FileOutputStream。

    String fileName = url.getFile();
    String destName = "qr.png";
    System.out.println(destName);

    InputStream is = null;
    try {
        is = url.openStream();
    } catch (IOException e) {
        e.printStackTrace();
    }
    OutputStream os = new FileOutputStream(destName);

    byte[] b = new byte[2048];
    int length;

    while ((length = is.read(b)) != -1) {
        os.write(b, 0, length);
    }

    is.close();
    os.close();
© www.soinside.com 2019 - 2024. All rights reserved.