Java-IO流综合操作

public class Demo4
{
    public static void JAVA_PC(String path) throws IOException
    {
        BufferedWriter wri=new BufferedWriter(new FileWriter("D://SUN_JD_2.txt"));
        InputStream is = new URL(path).openStream();//此为字节流,但是包含中文字符,会乱码
        InputStreamReader INp = new InputStreamReader(is, "UTF-8");//全部转换为字节
        BufferedReader read = new BufferedReader(INp);
        String S = null;
        while ((S = read.readLine()) != null)
        {
            System.out.println(S);
            wri.write(S);
            wri.newLine();
        }
        wri.flush();
        read.close();
        INp.close();
        is.close();
        wri.close();
    }
    
    public static void main(String[] args) throws IOException
    {
        JAVA_PC("https://www.jd.com");
        System.out.println("爬虫完成");
    }
}

最简单的爬虫思维,很多流的问题,这个看明白的话IO流就搞得不错了

上一篇:默写


下一篇:days05