论坛首页 Java企业应用论坛

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

浏览 3758 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2006-11-16  
如: <!---->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. }  
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics