Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Convert file from any encoding to UTF-8

  1. #1
    Banned
    Join Date
    May 2011
    Posts
    26
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Convert file from any encoding to UTF-8

    I have files that are either encoded in ASCII (Windows-1252) or UTF-8 (with or without BOM encoding). How can I convert them from their encoding to UTF-8, like I could do with text editors like Notepad++?

    Sin título.jpg


  2. #2
    Junior Member Mrc0d3r's Avatar
    Join Date
    Jun 2011
    Location
    TCP/IP Layer 3
    Posts
    25
    My Mood
    Bored
    Thanks
    0
    Thanked 6 Times in 5 Posts

    Default Re: Convert file from any encoding to UTF-8

    You can establish an input stream to the original file and fetch the data, then place it in an output steam with UTF-8 encoding.
    Example of the output stream creation.

  3. The Following User Says Thank You to Mrc0d3r For This Useful Post:

    efluvio (June 26th, 2011)

  4. #3
    Banned
    Join Date
    May 2011
    Posts
    26
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Convert file from any encoding to UTF-8

    Quote Originally Posted by Mrc0d3r View Post
    You can establish an input stream to the original file and fetch the data, then place it in an output steam with UTF-8 encoding.
    Example of the output stream creation.
    Thank you. I've found that when specifying encoding for the output is necessary as well to specify it for the input:
    BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(file), encType));

    The encType can be obtained from org.mozilla.universalchardet.UniversalDetector
    juniversalchardet - Java port of universalchardet - Google Project Hosting

    If encType is null don't specify encoding.

Similar Threads

  1. Change file encoding from ANSI to UTF-8
    By efluvio in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: June 19th, 2011, 02:48 PM
  2. Write to pdf file with pdfbox with greek encoding
    By javment in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: March 16th, 2011, 09:57 AM
  3. How do you convert a jar file into a java file, how ?
    By auto78900 in forum Java Theory & Questions
    Replies: 4
    Last Post: October 12th, 2010, 01:32 AM
  4. [SOLVED] Convert JFrame graphics into a jpeg file
    By Perd1t1on in forum AWT / Java Swing
    Replies: 4
    Last Post: June 22nd, 2010, 06:21 PM
  5. How to Convert DWG File to an Image
    By lance9200 in forum Java Theory & Questions
    Replies: 0
    Last Post: June 17th, 2010, 11:21 AM