PushbackInputStream 读取GBK字符时,会将双引号变成单引号

如: xml version="1.0" encoding="GBK"
PushbackInputStream 读取后,会变成:  xml version='1.0' encoding='GBK'
而UTF-8不会!
java 代码
  1. public static void  testStream() throws IOException{   
  2.     int MAX=2048;   
  3.     URL url=new URL("http://www.open-open.com/indexrss.xml");   
  4. /       URL url=new URL("http://www.blogjava.net/kukoo/Rss.aspx");   
  5.     InputStream input=url.openStream();   
  6.     byte bytes[]=new byte[MAX];   
  7.     PushbackInputStream bfInput=new PushbackInputStream(input);   
  8.     OutputStream out=new FileOutputStream(new File("e:/temp/rss.xml"));   
  9.     BufferedOutputStream bfOut=new BufferedOutputStream(out);   
  10.     int read=0;   
  11.     int totalBytes=0;          
  12.     int offset = 0;   
  13.     int max = MAX;   
  14.     while((read=bfInput.read(bytes,offset,max))!=-1&&offset
  15.         totalBytes+=read;   
  16.         bfOut.write(bytes, offset, max);   
  17.         offset+=read;              
  18.         max-=read;             
  19.         System.out.println("read:"+read+"total:"+totalBytes);   
  20.     }   
  21.        
  22.     System.out.println(read+":"+totalBytes);   
  23.     bfOut.flush();   
  24.     bfOut.close();   
  25.     bfInput.close();   
  26.     Reader reader=new InputStreamReader(new ByteArrayInputStream(bytes,0,offset));   
  27.     BufferedReader bufferReader=new BufferedReader(reader);   
  28.     String longer=bufferReader.readLine();   
  29.     System.out.println(""+longer);   
  30. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值