List of utility methods to do Write String to File
void | writeFile(File file, String... lines) write File PrintStream out = new PrintStream(new FileOutputStream(file)); for (String line : lines) out.println(line); out.flush(); out.close(); |
void | writeFile(File file, StringBuffer buffer) write File writeFile(file, buffer.toString()); |
void | writeFile(File filename, ArrayList lines) writes ArrayList into file. try { FileWriter fw = new FileWriter(filename); for (int i = 0; i < lines.size(); i++) fw.write((String) lines.get(i) + "\n"); fw.close(); } catch (IOException e) { System.err.println("error writing file"); e.printStackTrace(); ... |
File | writeFile(final File file, final String content) write File try { if (file.exists()) { file.delete(); final File parent = file.getParentFile(); if (!parent.exists()) { parent.mkdirs(); final FileWriter fw = new FileWriter(file); fw.write(content); fw.close(); return file; } catch (final IOException e) { throw new RuntimeException("Error in tests!", e); |
void | writeFile(final File file, final String contents) write File final File dir = file.getParentFile(); if (dir != null && !dir.isDirectory() && !dir.mkdirs()) throw new IOException("Could not make " + dir); final FileWriter writer = new FileWriter(file); writer.write(contents); writer.close(); |
void | writeFile(final File file, final String contents) write File final File result = new File(file.getAbsoluteFile().getParentFile(), file.getName() + ".new"); final FileOutputStream out = new FileOutputStream(result); out.write(contents.getBytes()); out.close(); result.renameTo(file); |
void | writeFile(final File iFile, final String iContent) write File final FileOutputStream fos = new FileOutputStream(iFile); try { final OutputStreamWriter os = new OutputStreamWriter(fos); try { final BufferedWriter writer = new BufferedWriter(os); try { writer.write(iContent); } finally { ... |
void | writeFile(String absoluteFileName, String content, boolean append) Writes a string to file FileWriter fw = null; Writer writer = null; try { fw = new FileWriter(absoluteFileName, append); writer = new BufferedWriter(fw); writer.write(content); } finally { if (writer != null) ... |
void | writeFile(String aContent, String aFileName) This function takes a String with some content and a String which is the filename, writes the content to the file using UTF-8 encoding and finally closes the file. BufferedWriter fr = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(aFileName), "UTF8")); fr.write(aContent); fr.close(); |
boolean | writeFile(String aInFilePath, String aInContent) write File boolean lStatus = false; try { FileWriter lWriter = new FileWriter(aInFilePath); lWriter.append(aInContent); lWriter.flush(); lWriter.close(); lStatus = true; } catch (Exception ex) { ... |