java抓取网页,打印时乱码,该如何处理

java抓取网页,打印时乱码下面的方法是把网页保存到SD卡一个文件中,打开时没有乱码,打印时却有乱码。//将页

java抓取网页,打印时乱码
下面的方法是把网页保存到SD卡一个文件中,打开时没有乱码,打印时却有乱码。
//将页面保存到本地文件夹
    public void doWrite(String url_str)
    {
    URL url = null;

    FileOutputStream fos = null;

    InputStream is;

    try {

    for (int i = 0; i < 1; i++) {

    url = new URL(url_str);
    ByteArrayOutputStream data=new ByteArrayOutputStream();

    byte bytes[] = new byte[1024 * 2000];

    int index = 0;

    is = url.openStream();

    int count = is.read(bytes, index, 1024 * 2000);

    while (count != -1) {

    index += count;

    count = is.read(bytes, index, 1);

    }
    
    url1=System.currentTimeMillis();//保存名设置

    fos = new FileOutputStream("sdcard/dyhtml/"+url1+".html");
    fos.write(bytes, 0, index);
    
    is.close();
    fos.close();
    }
    }catch (MalformedURLException e) {

    e.printStackTrace();

    } catch (IOException e) {

    e.printStackTrace();

    }
  
    } Java 乱码
[解决办法]
java 默认utf-8,试试抓一个utf8的网页看看
[解决办法]
可以指定编码

new FileOutputStream("out.txt"),"GB2312")

------解决方案--------------------


设置输出时的编码,如果没有设置的话,就默认使用你系统的编码了
因为你系统的编码与网页内容的编码不一致,所以输出乱码


BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("out.txt"),"GBK"));