java _io_转换流输出,将读取的百度源码输入到文件
可以指定输出内容的字符集
不加装饰器:
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("操作异常");}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。