Java Path File Content writeFile(String path, String contents)

Here you can find the source of writeFile(String path, String contents)

Description

write File

License

Open Source License

Declaration

public static void writeFile(String path, String contents) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;

public class Main {
    public static void writeFile(String path, String contents) {
        Path p = FileSystems.getDefault().getPath(path);
        writeFile(p, contents);//  w ww.ja v  a  2 s  .c  om
    }

    public static void writeFile(Path p, String contents) {
        try {
            Files.deleteIfExists(p);
            Files.write(p, contents.getBytes());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. writeFile(Path filePath, String content)
  2. writeFile(Path path, String content)
  3. writeFile(Path path, String contents)
  4. writeFile(String path, String content)
  5. writeFile(String path, String content)
  6. writeFileContents(Path to, byte[] contents)
  7. writeJsonToFile(Path jsonPath, String jsonContent)
  8. writeLines(Path base, String file, String[] content)
  9. writeString(String content, Path path)