【问题标题】:XAMPP/MySQL Downloading images error - JavaXAMPP/MySQL 下载图像错误 - Java
【发布时间】:2015-01-16 11:58:02
【问题描述】:

我的程序有一部分可以检查文件夹中是否缺少任何图片,如果缺少则下载它们。它工作得很好,除非每当我尝试查看这些图像时,我的图片查看器(InfranView 和 Windows 照片查看器)都会给我以下错误:

http://imgur.com/sqzSoI3&V0TSV1m

我查看了文件的托管位置(C:\xampp\htdocs 文件夹)并查看了那里的图像,但它们没有损坏。

http://imgur.com/sqzSoI3&V0TSV1m#1

如果您能帮我找到解决方案,我将不胜感激。

编辑:this 教程之后找到了解决方案。在下面发布了planetjone代码的摘录。有帮助的帮助!

解决方案:

public void downloadMissingFiles(String urls, String destination)
        throws IOException {
    URL url = new URL(urls);
    InputStream in = new BufferedInputStream(url.openStream());
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    byte[] buf = new byte[1024];
    int n = 0;
    while (-1!=(n=in.read(buf)))
    {
       out.write(buf, 0, n);
    }
    out.close();
    in.close();
    byte[] response = out.toByteArray();
    FileOutputStream fos = new FileOutputStream(destination);
    fos.write(response);
    fos.close();
}

【问题讨论】:

    标签: java mysql image xampp imagedownload


    【解决方案1】:

    解决方案:

    public void downloadMissingFiles(String urls, String destination)
            throws IOException {
        URL url = new URL(urls);
        InputStream in = new BufferedInputStream(url.openStream());
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        byte[] buf = new byte[1024];
        int n = 0;
        while (-1!=(n=in.read(buf)))
        {
           out.write(buf, 0, n);
        }
        out.close();
        in.close();
        byte[] response = out.toByteArray();
        FileOutputStream fos = new FileOutputStream(destination);
        fos.write(response);
        fos.close();
    }
    

    【讨论】:

      猜你喜欢
      • 2016-01-18
      • 2014-03-05
      • 1970-01-01
      • 2017-11-27
      • 2017-06-25
      • 2015-01-23
      • 2018-05-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多