List of utility methods to do Text File Write nio
void | writeTextFile(String file, String articleContent) write Text File PrintWriter out = new PrintWriter( new OutputStreamWriter(new FileOutputStream(file), Charset.forName("UTF-8"))); out.println(articleContent); out.close(); if (out.checkError()) { throw new IOException("Error saving " + file); |
void | writeTo(File file, String content) write To Path path = file.toPath(); writeTo(path, content); |
void | writeToFile(File file, String content) Writes given string to a file. createFile(file); Files.write(file.toPath(), content.getBytes(CHARSET)); |
void | writeToFile(File file, String str) write To File if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); if (!file.exists()) { try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); ... |
void | writeToFile(final File file, final String data) Write a UTF-8 string to a file object. writeToFile(file.toPath(), data); |
File | writeToFile(String content, String fileName) Creates file under temporary file directory and writes configuration to it. File temp = null; BufferedWriter bw = null; try { temp = new File(System.getProperty("java.io.tmpdir") + File.separator + fileName); bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(temp), StandardCharsets.UTF_8)); bw.write(content); bw.flush(); } catch (RuntimeException e) { ... |
void | writeToFile(String content, String fileName, boolean createFile) write To File writeToFile(content.getBytes(DEFAULT_UTF_8_CHARSET), fileName, createFile); |
void | writeToFile(String filename, String fileContents) write To File Writer writer = null; try { writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(filename), StandardCharsets.US_ASCII)); writer.write(fileContents); } catch (IOException e) { e.printStackTrace(); } finally { ... |
boolean | writeToFile(String filename, String... lines) write To File Path p = Paths.get(filename); try (BufferedWriter bw = new BufferedWriter(Files.newBufferedWriter(p))) { for (String l : lines) { bw.write(l); bw.newLine(); } catch (IOException ex) { return false; ... |
void | writeTokenText(OutputStream theOs, String theStr) write Token Text theOs.write(theStr.getBytes(StandardCharsets.UTF_8)); theOs.write(0x00); |