my dog learned polymorphism*
The moose likes I/O and Streams and the fly likes Problem with charset while writing String to File Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Problem with charset while writing String to File" Watch "Problem with charset while writing String to File" New topic
Author

Problem with charset while writing String to File

Brian Nguyen
Greenhorn

Joined: Mar 19, 2002
Posts: 22
Hi All,
I am trying to write a method that writes a String into a file:
--------------------------------------------------------------
private synchronized void saveTicketsToFile(String inTickets){
try{
String fullPathFilename = "D:/learn/e_ticket.dat";
BufferedWriter writer = new BufferedWriter(new FileWriter(fullPathFilename));
writer.write(inTickets);
writer.flush();
writer.close();
} catch (Exception e){
System.out.println("ERROR: " + e);
e.printStackTrace();
}

--------------------------------------------------------------
However, everytime I run this program, I always have the following error:
ERROR: java.lang.IllegalArgumentException: Null charset name

Here is the stack trace that I have:
at java.nio.charset.Charset.lookup(Charset.java:376)
at java.nio.charset.Charset.isSupported(Charset.java:405)
at sun.nio.cs.StreamEncoder.forOutputStreamWriter(StreamEncoder.java:68)
at java.io.OutputStreamWriter.<init>(OutputStreamWriter.java:93)
at java.io.FileWriter.<init>(FileWriter.java:61)


So I am wondering if anyone could explain why I have that problem with Charset?
Thank you very much for your help!
Brian

[ October 11, 2004: Message edited by: Brian Nguyen ]
[ October 11, 2004: Message edited by: Brian Nguyen ]
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8935
    
    9

Never seen anything like that. Are you doing anything strange with locale settings? Will your code work on a different computer? Your JDK or JRE may be screwed up.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with charset while writing String to File