How to save webpages without modifying their original charset?
I am writing a java project saving Chinese webpages.
My local OS default charset is gb2312, the Chinese national standard charset.
First I load the specified webpages to a StringBuffer, then flush the buffer to a specifed file.
Critical codes are below:
The webpages are originally encoded in UTF-8, but after being saved, they are transferred to gb2312,
public static StringBuffer webPage2Buffer(URL url,String encoding)
//String encoding = "UTF-8";
StringBuffer result=new StringBuffer();
BufferedReader buffRead = new BufferedReader(new InputStreamReader(in, encoding));
while((c=buffRead.read())!=-1) result.append((char) c);
public static void Buffer2File(StringBuffer strBuf,String writeTime, String storingPlace)
File rltFile = new File(storingPlace+writeTime+".html");
PrintWriter printer = new PrintWriter(rltFile);
catch (IOException e1)
which is not wanted. What should I do to save them without modifying the original charset?
Hope can help!
PrintWriter printer = new PrintWriter( new OutputStreamWriter( new FileOutputStream(rltFile), "UTF-8"));
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)