Solve the problem of reading and writing UTF-8 files in Eclipse when Java project is exported to jar package

Source: Internet
Author: User

Recently encountered a small problem, it is normal to read and write txt files in the UTF-8 format in the Eclipse environment, but when exported to a jar package, there are some Chinese garbled problems when reading and writing files by clicking.


Workaround:

Started with FileReader and FileWriter to read and write, later changed to use InputStreamReader and outputstreamwriter after the problem solved


Key code:

BufferedReader reader; BufferedWriter Writer;//reader = new BufferedReader (new FileReader (New File (Filedir,filename))); reader = new BufferedReader (New InputStreamReader (New FileInputStream (Filedir,filename), "UTF-8"));//writer = new BufferedWriter (New FileWriter (New File (filedir,emaildomain+ ". txt"), true)); writer = new BufferedWriter (new OutputStreamWriter (New FileOutputStream (New File (filedir,emaildomain+ ". txt"), true), "UTF-8");

(PS: Do not control the code in the specific file path and file name, to understand the idea can be)

This article is from the "Zifangsky" blog, make sure to keep this source http://983836259.blog.51cto.com/7311475/1661761

Solve the problem of reading and writing UTF-8 files in Eclipse when Java project is exported to jar package

Related Article

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.