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.


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

Results 1 to 1 of 1

Thread: How to set character encoding of FileWriter

  1. #1
    Junior Member
    Join Date
    Dec 2012
    My Mood
    Thanked 0 Times in 0 Posts

    Default How to set character encoding of FileWriter

    Update: I found a solution here, http://stackoverflow.com/questions/9...ilewriter-java

    I have the following code to write a file of lottery tickets from an ArrayList, and it's working fine.

            // Print lotto tickets to file
            try (FileWriter writer = new FileWriter("lottotickets.txt")) 
                for (String ticket : ticketPool) {
                    writer.write(ticket + "\n");
                    //System.out.println(ticket + "\n");            

    However, when I use NetBeans IDE to inspect my code it gives me the following error:

    Reliance on default encoding
    Found a call to a method which will perform a byte to String (or String to byte) conversion, and will assume that the default platform encoding is suitable. This will cause the application behaviour to vary between platforms. Use an alternative API and specify a charset name or Charset object explicitly.

    I have been searching for how to fix this but not luck so far. Any help would be much appreciated.
    Last edited by gkokaisel; December 9th, 2012 at 00:15. Reason: Solved my problem

Similar Threads

  1. Help with character encoding
    By IHeartProgramming in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 20th, 2012, 20:19
  2. [SOLVED] Fliereader/Filewriter (Need Help!)
    By Techsam in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 12th, 2012, 20:22
  3. invalid encoding for signature
    By Silvery in forum JDBC & Databases
    Replies: 2
    Last Post: July 2nd, 2012, 15:20
  4. Problem with Japanese Encoding
    By sendhilpk in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: January 12th, 2010, 01:57
  5. The character '' is an invalid XML character exception getting
    By sumanta in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 9th, 2010, 11:13

Tags for this Thread