Java Utililty Methods Path File Write nio

List of utility methods to do Path File Write nio

Description

The list of methods to do Path File Write nio are organized into topic(s).

Method

voidwrite(Object obj, String filePath)
write
Path path = Paths.get(filePath);
try (ObjectOutputStream output = new ObjectOutputStream(Files.newOutputStream(path))) {
    output.writeObject(obj);
voidwrite(Path p)
write
try {
    Files.write(p, BODY, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
} catch (IOException ex) {
    throw new UncheckedIOException(ex);
voidwrite(Path p, String s)
Writes the specified string to a file.
try (BufferedWriter writer = Files.newBufferedWriter(p, Charset.forName("UTF-8"), StandardOpenOption.CREATE,
        StandardOpenOption.TRUNCATE_EXISTING)) {
    writer.write(s, 0, s.length());
voidwrite(Path path, String string)
write
PrintWriter out = null;
try {
    out = new PrintWriter(Files.newOutputStream(path));
    out.write(string);
} finally {
    if (out != null) {
        out.close();
ProcesswriteAudio(String source, String writePath)
write Audio
String command = "\"" + WRITER_PATH + "\" \"" + source + "\" " + writePath + "";
Process process = null;
try {
    process = Runtime.getRuntime().exec(command);
    printErrorStream(process);
} catch (IOException e) {
    e.printStackTrace();
return process;
booleanwriteEndStringInFile(Path path, String s)
write End String In File
FileWriter writer;
try {
    writer = new FileWriter(path.toFile(), true);
    writer.write(s + "\n");
    writer.close();
    return true;
} catch (IOException e) {
    e.printStackTrace();
...
voidwriteFile(String filePath, String text)
Writes a string to the specified file using the default encoding.
writeFile(filePath, text, null);
voidwriteFile(String path, String output)
write File
Writer writer = new OutputStreamWriter(new FileOutputStream(path), UTF8);
try {
    writer.write(output);
} finally {
    writer.close();
voidwriteFile(String payload, Path balOutPath)
Method is responsible of writing the bal string payload to .bal file.
PrintWriter writer = new PrintWriter(balOutPath.toFile(), "UTF-8");
writer.print(payload);
writer.close();
voidwriteFileToArchive(final ZipOutputStream zos, final Path baseSrcPath, final Path filePath)
write File To Archive
final byte[] buffer = new byte[1024];
final String zipPath = baseSrcPath.resolve(extractLanguageRelativePath(filePath)).toString();
final ZipEntry ze = new ZipEntry(zipPath);
zos.putNextEntry(ze);
try (InputStream in = Files.newInputStream(filePath);) {
    int len;
    while ((len = in.read(buffer)) > 0) {
        zos.write(buffer, 0, len);
...