List of usage examples for java.io FileWriter getEncoding
public String getEncoding()
From source file:gov.nasa.ensemble.dictionary.nddl.ModelGenerator.java
private static StringBuilder readModelFile(File file) throws IOException { StringBuilder result = new StringBuilder(); FileInputStream fis = null;/* ww w . j a va 2s.c om*/ InputStreamReader reader = null; int size; try { char[] buffer = new char[1024]; fis = new FileInputStream(file); FileWriter filewriter = new FileWriter("out"); String encname = filewriter.getEncoding(); filewriter.close(); Charset cs = Charset.forName(encname); CharsetDecoder csd = cs.newDecoder(); csd.onMalformedInput(CodingErrorAction.REPLACE); reader = new InputStreamReader(fis, csd); while ((size = reader.read(buffer, 0, 1024)) > 0) { result.append(buffer, 0, size); } } catch (Exception e) { // System.out.println(encoding); e.printStackTrace(); } finally { if (fis != null) { fis.close(); } if (reader != null) { reader.close(); } } return result; }