List of utility methods to do Text File Write
void | writeStringToFile(String str, File file) write String To File OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); char[] chars = str.toCharArray(); out.write(chars, 0, chars.length); out.close(); |
File | writeStringToFile(String str, File file) write String To File try { BufferedReader in4 = new BufferedReader(new StringReader(str)); PrintWriter out1 = new PrintWriter(new BufferedWriter(new FileWriter(file))); String tempStr = null; while ((tempStr = in4.readLine()) != null) { out1.println(tempStr); out1.close(); ... |
void | WriteStringToFile(String str, String file) Write String To File try { BufferedWriter output = new BufferedWriter(new FileWriter(file)); output.write(str); output.flush(); output.close(); } catch (IOException e) { e.printStackTrace(); |
void | writeStringToFile(String str, String filePath) write String To File PrintWriter tmpASP; try { tmpASP = new PrintWriter(filePath); tmpASP.print(str); tmpASP.close(); } catch (FileNotFoundException e) { e.printStackTrace(); |
void | writeStringToFile(String str, String filePath) write String To File File file = new File(filePath); try { BufferedWriter out = new BufferedWriter(new FileWriter(file, false)); out.write(str); out.close(); } catch (IOException e) { e.printStackTrace(); |
void | writeStringToFile(String string, File destFile) Includes workaround for bug: http://bugs.sun.com/bugdatabase/view_bug.do;:YfiG?bug_id=4117557 try { final FileOutputStream fos = new FileOutputStream(destFile.getAbsoluteFile()); final BufferedWriter bw = new BufferedWriter(new PrintWriter(fos)); bw.write(string); bw.flush(); bw.close(); fos.close(); } catch (FileNotFoundException e) { ... |
void | writeStringToFile(String string, File dstFile) Writes the string to dstFile try (BufferedWriter bufferedwriter = new BufferedWriter(new FileWriter(dstFile));) { bufferedwriter.write(string); } catch (FileNotFoundException e) { throw new RuntimeException("Filed does not exist " + dstFile.getAbsolutePath()); } catch (IOException e) { throw new RuntimeException("Could not write to file " + dstFile.getAbsolutePath()); |
void | writeStringToFile(String string, File file) Writes a string to the file at the specified path, overwriting it if it already exists. try { BufferedWriter writer = new BufferedWriter(new FileWriter(file)); writer.write(string); writer.close(); } catch (IOException e) { |
void | writeStringToFile(String string, File file) write String To File FileWriter fw = new FileWriter(file);
fw.append(string);
fw.close();
|
File | writeStringToFile(String string, File file) write String To File try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8")) { writer.write(string); return file; |