SHARE
TWEET

write String to file

DulcetAirman Jul 20th, 2017 (edited) 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top