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:
[CODE] public static StringBuffer webPage2Buffer(URL url,String encoding)
throws IOException
{
//String encoding = “UTF-8”;
StringBuffer result=new StringBuffer();
InputStream in=url.openStream();
BufferedReader buffRead = new BufferedReader(new InputStreamReader(in, encoding));
int c;
while((c=buffRead.read())!=-1) result.append((char) c);
return result;
}
public static void Buffer2File(StringBuffer strBuf,String writeTime, String storingPlace)
{
File rltFile = new File(storingPlace+writeTime+”.html”);
try
{
PrintWriter printer = new PrintWriter(rltFile);
printer.println(strBuf.toString());
printer.close();
}
catch (IOException e1)
{
e1.printStackTrace();
};
}
The webpages are originally encoded in UTF-8, but after being saved, they are transferred to gb2312,
which is not wanted. What should I do to save them without modifying the original charset?
Thanks!?