Java Code Examples for java.io.FileWriter.getEncoding()

The following are Jave code examples for showing how to use getEncoding() of the java.io.FileWriter class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: powertext   File: TextEditorPane.java   View Source Code Vote up 6 votes
/**
 * Returns the default encoding for this operating system.
 *
 * @return The default encoding.
 */
private static String getDefaultEncoding() {
	// NOTE:  The "file.encoding" system property is not guaranteed to be
	// set by the spec, so we cannot rely on it.
	String encoding = Charset.defaultCharset().name();
	if (encoding==null) {
		try {
			File f = File.createTempFile("rsta", null);
			FileWriter w = new FileWriter(f);
			encoding = w.getEncoding();
			w.close();
			f.deleteOnExit();//delete();  Keep FindBugs happy
		} catch (IOException ioe) {
			encoding = "US-ASCII";
		}
	}
	return encoding;
}