可以指定输出内容的字符集
不加装饰器:
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("操作异常");
}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。