/** * 获取url访问的文件的内容类型 */ public class Demo { public static void main(String[] args) throws IOException { BufferedInputStream bis = null; HttpURLConnection urlconnection = null; URL url = null; url = new URL("http://yuncode.net"); urlconnection = (HttpURLConnection) url.openConnection(); urlconnection.connect(); bis = new BufferedInputStream(urlconnection.getInputStream()); System.out.println("file type:" + HttpURLConnection.guessContentTypeFromStream(bis)); // 获取url访问的文件的内容类型 } }