java - 如何检查图像是否存在于特定位置?

标签 java file

除了下面的代码之外,还有什么方法可以检查图像是否存在于特定位置?此代码花费了太多时间。

  static boolean isImage(String image_path){  
    InputStream input = null;
    try{

        URL url = new URL(image_path);
        input = url.openStream();
        return  true;

    }catch(Exception ex){
        return  false;
    }

  }

最佳答案

如果您只想检查文件是否存在:

static boolean isImage(String image_path){  
    try{
        File f = new File(image_path);
        return  f.exists();

    }catch(Exception ex){
        return  false;
    }
}

关于java - 如何检查图像是否存在于特定位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28360505/

相关文章:

html - 如何禁用IE中的文件输入文本框?

java - 各处边距 8 dp,顶部、右侧、左侧和底部

java - 如何使用私钥通过quickfix连接服务器

java - javaFX 8 中 @NamedArg 注释的用途是什么?

python - 使用 blobstore 处理程序获取上传文件的链接

C程序写最后几行程序,求错误?

java - Web 应用程序中的 RandomStringUtils.random 奇怪行为

java - else on if 语句没有通过

file - 大型 clojure 项目是如何组织的?

file - 在 cocoa 中保存文件