Use Java to convert the file encoding from GBK to utf8

Source: Internet
Author: User

Http://blog.csdn.net/laorer/archive/2009/02/08/3868962.aspx

 

It solved a big problem. Thank you very much. Code-generated Java and JSP are no longer manually transcoded.

 

Core code:

Private Static void transferfile (string srcfilename, string destfilename) throws ioexception {
String line_separator = system. getproperty ("line. separator ");
Fileinputstream FCM = new fileinputstream (srcfilename );
Stringbuffer content = new stringbuffer ();
Datainputstream in = new datainputstream (FCM );
Bufferedreader d = new bufferedreader (New inputstreamreader (in, "GBK"); //, "UTF-8"
String line = NULL;
While (line = D. Readline ())! = NULL)
Content. append (LINE + line_separator );
D. Close ();
In. Close ();
FCM. Close ();

Writer ow = new outputstreamwriter (New fileoutputstream (destfilename), "UTF-8 ");
Ow. Write (content. tostring ());
Ow. Close ();
}

 

Convert a GBK encoded file into a UTF-8 encoded file

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/laorer/archive/2009/02/08/3868962.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.