Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package StringToFile;
- import java.io.IOException;
- import java.nio.charset.Charset;
- import java.nio.file.Files;
- import java.nio.file.Paths;
- import java.util.List;
- public class StringToFile {
- public static void main(String[] args) throws IOException {
- }
- public static void write() throws IOException {
- String msg = "hello younthis is just a testn";
- Files.write(Paths.get("./duke.txt"), msg.getBytes());
- }
- public static void read() throws IOException {
- List < String > lines = Files.readAllLines(Paths.get("./duke.txt"), Charset.defaultCharset());
- for (String line: lines) {
- System.out.println("line read: " + line);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement