码迷,mamicode.com
首页 > 编程语言 > 详细

java _io_转换流输入,将读取的百度源码输入到文件

时间:2019-07-29 20:23:07      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:指定   http   pre   lin   ring   字符   NPU   输出内容   操作   

可以指定输出内容的字符集

不加装饰器:
OutputStreamWiter os = new OutputStreamWriter(new FileOutputStream("D:/d/baidu"),"UTF-8"); //不指定字符集,将默认为工程字符集

加装饰器:
BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(new FileOutputStream("D:/d/baidu"),"UTF-8") );

try(BufferedReader reader=new BufferedReader(new InputStreamReader(new URL("http://www.baidu.com").openStream(),"UTF-8"));
    BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(new FileOutputStream("D:/d/baidu.html"),"UTF-8")); //不指定字符集,默认是工程字符集
        )
{
    String s;
    while((s=reader.readLine())!=null)
    {
        writer.write(s);
        writer.newLine();
        writer.flush();
    }

}catch(IOException e)
{
    System.out.println("操作异常");
}

java _io_转换流输入,将读取的百度源码输入到文件

标签:指定   http   pre   lin   ring   字符   NPU   输出内容   操作   

原文地址:https://blog.51cto.com/14437184/2424581

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!