如何在Android上查看图片扩展名?

时间:2013-08-11 09:08:59

标签: android imagedownload

我正在从Facebook检索帖子,我想将数据保存在数据库中,但是对于图像和照片我需要下载它们但是我需要确定图像的扩展名但是使用拆分因为链接所以没有用处不同。有没有办法确定扩展名?

我的代码:

  public static String DownLoadFile(String netUrl, String savePath, String name, String ext) {
        try {
            URL url = new URL(netUrl);
            File file = new File(savePath, name + "." + ext);

   /* Open a connection to that URL. */
        URLConnection ucon = url.openConnection();

        InputStream is = ucon.getInputStream();

        BufferedInputStream bis = new BufferedInputStream(is);
        long startTime = System.currentTimeMillis();
        Log.d("DownloadManager", "download begining");
        Log.d("DownloadManager", "downloaded file name:" + name);


        ByteArrayBuffer baf = new ByteArrayBuffer(5000);
        int current = 0;
        while ((current = bis.read()) != -1) {
            baf.append((byte) current);
        }


           /* Convert the Bytes read to a String. */
        FileOutputStream fos = new FileOutputStream(file);
        fos.write(baf.toByteArray());
        fos.flush();
        fos.close();
        Log.d("DownloadManager", "download ready in" + ((System.currentTimeMillis() - startTime) / 1000) + " sec");

        return file.getAbsolutePath();


    } catch (Exception exx) {
        if (exx.getMessage() != null) {

            Log.w(Error_Tag, "Err3 = " + exx.getMessage());
        } else {
            Log.w(Error_Tag, "Err3 = " + exx.getMessage());

        }

    }

    return null;
}

1 个答案:

答案 0 :(得分:1)