小编sku*_*k a的帖子

使用Java在Base64中对URL中的图像进行编码

我想编码并保存Base64中的URL图像.我发现了几个从本地文件进行编码而不是从URL进行编码的示例.有可能这样做吗?

我尝试过类似的东西,但没有成功.任何线索,有帮助吗?感谢您的回答.

    public static void main(String[] args)  {
    String imageUrl = "http://www.avajava.com/images/avajavalogo.jpg";
    String destinationFile = "image.jpg";

    try {           
        // Reading a Image file from file system
        URL url = new URL(imageUrl);
        InputStream is = url.openStream();

        FileInputStream imageInFile = new FileInputStream(is.toString());
        byte imageData[] = new byte[2048];
        imageInFile.read(imageData);

        // Converting Image byte array into Base64 String
        String imageDataString = encodeImage(imageData);
        System.out.println("imageDataString : " + imageDataString);




        System.out.println("Image Successfully Manipulated!");
    } catch (FileNotFoundException e) {
        System.out.println("Image not found" + e);
    } catch (IOException ioe) …
Run Code Online (Sandbox Code Playgroud)

java base64 encode

5
推荐指数
4
解决办法
2万
查看次数

标签 统计

base64 ×1

encode ×1

java ×1