List of utility methods to do Text File Write
void | writeFileAsString(File file, String text) write File As String try { ensureWriteable(file); OutputStream os = new FileOutputStream(file); if (file.getName().endsWith(".gz")) { os = new GZIPOutputStream(os); PrintStream out = new PrintStream(os); out.print(text); ... |
void | writeFileAsString(File file, String text, String encoding) write File As String try { ensureWriteable(file); OutputStream os = new FileOutputStream(file); if (file.getName().endsWith(".gz")) { os = new GZIPOutputStream(os); PrintStream out = new PrintStream(os, true, encoding); out.print(text); ... |
void | writeFileAsString(String filename, String text) write File As String if (filename.startsWith(SERIALPREFIX)) { filename = serialFileName(filename); writeFileAsString(new File(filename), text); |
void | writeFileAsString(String filename, String text, String encoding) write File As String if (filename.startsWith(SERIALPREFIX)) { filename = serialFileName(filename); writeFileAsString(new File(filename), text, encoding); |
void | writeFileAsStringWorldWritable(File file, String text) write File As String World Writable ensureWorldWriteable(file); writeFileAsString(file, text); file.setWritable(true, false); |
void | writeFileAtomically(File file, String content, String encoding) Writes a string to a file, creating the directory if necessary. File parent = file.getParentFile(); if (!parent.exists()) { parent.mkdirs(); File tmpFile = File.createTempFile("GSFileUtilWFA", ".tmp", parent); try { Writer out = new OutputStreamWriter(new FileOutputStream( tmpFile), encoding); ... |
void | writeFileWithBom(File file, String content, String encoding) write File With Bom if (!file.exists()) { file.getParentFile().mkdirs(); FileOutputStream out = null; try { out = new FileOutputStream(file); writeBom(out, encoding); out.write(content.getBytes(encoding)); ... |
void | writeLargerTextFile(File file, List write Larger Text File try (BufferedWriter writer = Files.newBufferedWriter( Paths.get(file.getPath()), StandardCharsets.UTF_8)) { for (String line : aLines) { writer.write(line); writer.newLine(); |
void | writeLineTextFile(File file, String data) write Line Text File PrintWriter pw = null; try { pw = new PrintWriter(file); pw.print(data); pw.flush(); } catch (Exception e) { e.printStackTrace(); try { ... |
void | writeLineTextFile(File file, String[] dataArray) write Line Text File PrintWriter pw = null; try { pw = new PrintWriter(file); for (String data : dataArray) { pw.println(data); pw.flush(); } catch (Exception e) { ... |