Advertisement
DulcetAirman

write String to file

Jul 20th, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.58 KB | None | 0 0
  1. import java.io.BufferedWriter;
  2. import java.io.IOException;
  3. import java.nio.charset.Charset;
  4. import java.nio.charset.StandardCharsets;
  5. import java.nio.file.Files;
  6. import java.nio.file.Path;
  7. import java.nio.file.Paths;
  8.  
  9. class SomeClass {
  10.   public static void main(final String[] args) throws IOException {
  11.     final Path path = Paths.get("d:\\text.txt");
  12.     final Charset charset = StandardCharsets.UTF_8;
  13.     try (BufferedWriter w = Files.newBufferedWriter(path, charset)) {
  14.       w.append("some string");
  15.     }
  16.     Files.lines(path, charset).forEach(System.out::println);
  17.   }
  18.  
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement