java 判断url 是不是文件
发布网友
发布时间:2023-11-15 10:06
我来回答
共1个回答
热心网友
时间:2024-02-03 06:56
public class FileUtils {
/**
* 检测网络资源是否存在
*
* @param strUrl
* @return
*/
public static boolean isNetFileAvailable(String strUrl) {
InputStream netFileInputStream = null;
try {
URL url = new URL(strUrl);
URLConnection urlConn = url.openConnection();
netFileInputStream = urlConn.getInputStream();
if (null != netFileInputStream) {
return true;
} else {
return false;
}
} catch (IOException e) {
return false;
} finally {
try {
if (netFileInputStream != null)
netFileInputStream.close();
} catch (IOException e) {
}
}
}
}