List of utility methods to do File Write nio
void | writeFile(File file, String content) write File writeFile(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8), content); |
void | writeFile(File file, String content) write File Files.write(file.toPath(), content.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.APPEND, StandardOpenOption.WRITE); |
void | writeFile(File file, String text) write File Files.write(text, file, Charset.defaultCharset()); |
void | writeFile(FileObject fileObject, String content) Create a file using the javax.annotation.processing.Filer , look the example bellow JavaFileObject fileObject = processingEnv.getFiler().createSourceFile(fileName, originatingElements);
OutputStreamWriter osw = null; IOException exception = null; try { OutputStream os = fileObject.openOutputStream(); osw = new OutputStreamWriter(os, Charset.forName("UTF-8")); osw.write(content, 0, content.length()); } catch (IOException ex) { exception = ex; ... |
void | writeFile(List Writes content to targetFile. final PrintWriter writer = new PrintWriter(new FileWriter(new File(targetFile))); try { for (String line : content) { writer.println(line); } finally { writer.close(); |
void | writeFile(OutputStream file, List write File BufferedWriter bufferedWriter = null; try { bufferedWriter = new BufferedWriter(new OutputStreamWriter(file, Charset.defaultCharset())); for (String line : data) { bufferedWriter.write(line); bufferedWriter.write(S_NEWLINE); } catch (Exception e) { ... |
void | writeFile(String filename, byte file[]) write File java.nio.file.Path p = Paths.get(filename, new String[0]); Files.write(p, file, new OpenOption[] { StandardOpenOption.CREATE }); |
void | writeFile(String fileName, String content) write File try (OutputStream os = new FileOutputStream(fileName); PrintStream ps = new PrintStream(os, true, StandardCharsets.UTF_8.name())) { ps.print(content); } catch (IOException e) { throw new IllegalStateException(e); |
void | writeFile(String fileName, String content) write File writeFile(fileName, new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)));
|
void | writeFile(String folder, String aFileName, String aItem) write File Path path = Paths.get(folder, aFileName);
try (BufferedWriter writer = Files.newBufferedWriter(path, ENCODING)) {
writer.write(aItem);
writer.newLine();
|