Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. package StringToFile;
  2. import java.io.IOException;
  3. import java.nio.charset.Charset;
  4. import java.nio.file.Files;
  5. import java.nio.file.Paths;
  6. import java.util.List;
  7.  
  8. public class StringToFile {
  9. public static void main(String[] args) throws IOException {
  10. }
  11. public static void write() throws IOException {
  12. String msg = "hello younthis is just a testn";
  13. Files.write(Paths.get("./duke.txt"), msg.getBytes());
  14. }
  15. public static void read() throws IOException {
  16. List < String > lines = Files.readAllLines(Paths.get("./duke.txt"), Charset.defaultCharset());
  17. for (String line: lines) {
  18. System.out.println("line read: " + line);
  19. }
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement