List of usage examples for java.io FileWriter write
public void write(int c) throws IOException
From source file:Main.java
public static File saveText(String text) throws IOException { File f;//from www .jav a 2 s . c o m String filename; if (!isExternalStorageWritable()) throw new IOException("Storage not available"); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); filename = dateFormat.format(new Date()); f = new File(getAlbumStorageDir(FOLDER_NAME), "Message " + filename + ".txt"); FileWriter fw = new FileWriter(f); fw.write(text); fw.close(); return f; }
From source file:Main.java
public static void xmlToFile(Document doc, File file) { String xmlString = xmlToString(doc); try {//from w ww .j av a 2s . c o m FileWriter w = new FileWriter(file); w.write(xmlString); w.flush(); w.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void writeFile(String writr_str, boolean add) { try {/*from ww w . j a va 2 s . c o m*/ FileWriter fout = new FileWriter(mFilePath, add); fout.write(writr_str); if (add) { fout.write("\r\n"); } else { } fout.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
static public void savelog(String processedStr) { String fullFilename = "D:/test.txt"; try {// ww w .j a 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: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 v a2s . c o m*/ String string = sw.toString(); FileWriter fw = new FileWriter(new File(path)); fw.write(string); fw.close(); }
From source file:Main.java
public static void createNewResultFileForConnexion() { Date currentDate = new Date(); SimpleDateFormat localDateFormat = new SimpleDateFormat("yyyyMMdd"); String logPath = LOG_FOLDER + "result_" + localDateFormat.format(currentDate) + "_" + System.currentTimeMillis() + ".txt"; try {//from w w w . java 2 s .c o m File logFile = new File(logPath); FileWriter writer = new FileWriter(logFile, Boolean.TRUE); writer.write("Command\tCommand(hex)\tResult\tResult(Hex)\tLatency\n"); writer.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static boolean writeOneLine(String fname, String value) { if (!new File(fname).exists()) { return false; }/*from w w w . j a v a2 s . c o m*/ 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(String in, File file, boolean append) { if (file.exists()) { file.delete();//from w w w . jav a2 s .c o m } try { file.createNewFile(); FileWriter fw = new FileWriter(file, append); fw.write(in); fw.flush(); fw.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void writeJsonOnDisk(Context context, String fileName, StringBuilder bigStr) { try {//from www . j a v a 2s.c o m FileWriter Filewriter = new FileWriter(context.getApplicationInfo().dataDir + "/" + fileName + ".json"); Filewriter.write(bigStr.toString()); Filewriter.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static boolean writeString(String filePath, String content) { File file = new File(filePath); if (!file.getParentFile().exists()) file.getParentFile().mkdirs();//from www . j ava 2 s . co m FileWriter writer = null; try { writer = new FileWriter(file); writer.write(content); } catch (IOException e) { } finally { try { if (writer != null) { writer.close(); return true; } } catch (IOException e) { } } return false; }