List of usage examples for java.io FileWriter close
public void close() throws IOException
From source file:Main.java
public static void writeStringAsFile(final String fileContents, String fileName) { try {//from ww w. j ava 2s .com String path = Environment.getExternalStorageDirectory().getAbsolutePath(); FileWriter out = new FileWriter(new File(path, fileName)); out.write(fileContents); out.close(); } catch (IOException e) { //!TODO } }
From source file:Main.java
public static void putString(File file, String contents) throws IOException { FileWriter output = new FileWriter(file); output.write(contents, 0, contents.length()); output.close(); }
From source file:Main.java
public static void saveDocument(Document document, String path) throws TransformerConfigurationException, TransformerFactoryConfigurationError, TransformerFactoryConfigurationError, TransformerException, IOException { StringWriter sw = new StringWriter(); StreamResult sr = new StreamResult(sw); DOMSource dom = new DOMSource(document); TransformerFactory transformerFactory = TransformerFactory.newInstance(); transformerFactory.setAttribute("indent-number", 4); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.transform(dom, sr);// ww w .j a va 2s . c o m String string = sw.toString(); FileWriter fw = new FileWriter(new File(path)); fw.write(string); fw.close(); }
From source file:Main.java
static public void savelog(String processedStr) { String fullFilename = "D:/test.txt"; try {/* w w w . ja v a 2 s. c o m*/ File newTextFile = new File(fullFilename); FileWriter fw; fw = new FileWriter(newTextFile); fw.write(processedStr); fw.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:LoadSave.java
public static void doSaveCommand(JTextComponent textComponent, String filename) throws Exception { FileWriter writer = null; writer = new FileWriter(filename); textComponent.write(writer);/*from ww w .ja v a 2 s. c om*/ writer.close(); }
From source file:Main.java
public static void xmlToFile(Document doc, File file) { String xmlString = xmlToString(doc); try {//from ww w. j a va 2s. c om FileWriter w = new FileWriter(file); w.write(xmlString); w.flush(); w.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
static void setSetting(String name, String data) { try {//from ww w . j a va 2 s. co m File root = new File(Environment.getExternalStorageDirectory().toString(), ".Instagram"); if (!root.exists()) { root.mkdirs(); } File gpxfile = new File(root, name + ".txt"); FileWriter writer = new FileWriter(gpxfile); writer.append(data); writer.flush(); writer.close(); } catch (IOException e) { } }
From source file:Main.java
public static boolean writeLineToFile(File file, String line, boolean append) { try {/*from w w w. j a va 2 s . co m*/ FileWriter fileWriter = new FileWriter(file, append); fileWriter.append(line + "\r\n"); fileWriter.flush(); fileWriter.close(); return true; } catch (IOException e) { e.printStackTrace(); return false; } }
From source file:Main.java
public static boolean writeOneLine(String fname, String value) { if (!new File(fname).exists()) { return false; }//from www . ja v a 2s. c om try { FileWriter fw = new FileWriter(fname); try { fw.write(value); } finally { fw.close(); } } catch (IOException e) { String Error = "Error writing to " + fname + ". Exception: "; Log.e("TAG", Error, e); return false; } return true; }
From source file:Main.java
public static void write(Element root, String xmlPath) { try {//from ww w .j ava 2 s. c om Document doc = root.getOwnerDocument(); TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); transformer.setOutputProperty("encoding", "utf-8"); FileWriter fw = new FileWriter(xmlPath); transformer.transform(new DOMSource(doc), new StreamResult(fw)); fw.close(); } catch (Exception e) { e.printStackTrace(); } }