java 抓取网页乱码问题处理

    技术2022-05-11  47

    String htmlContent = "";     java.io.InputStream inputStream;     java.net.URL url = new java.net.URL(" www.csdn.net ");     java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();     connection.connect();     inputStream = connection.getInputStream();     byte bytes[] = new byte[1024*100];     int index = 0;     int count = inputStream.read(bytes, index, 1024*100);     while (count != -1) {       index += count;       count = inputStream.read(bytes, index, 1);     }     System.out.println (count);     htmlContent = new String(bytes, "gb2312");//     System.out.println(htmlContent);  

    最新回复(0)