Last active
June 19, 2019 23:15
-
-
Save indrayam/ca8d39b931c4e14ab242ffb6c440ffda to your computer and use it in GitHub Desktop.
Simplest FileIO in Java (Part 1)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package dev.anandsharma.corejava.ch3; | |
import java.io.IOException; | |
import java.io.PrintWriter; | |
import java.nio.charset.StandardCharsets; | |
import java.nio.file.Path; | |
import java.util.Scanner; | |
public class FileIOTest1 { | |
public static final String RW_FILE_PATH = "/Users/anasharm/Downloads/test1.txt"; | |
public static void main(String[] args) throws IOException { | |
PrintWriter pw = new PrintWriter(RW_FILE_PATH, StandardCharsets.UTF_8); | |
pw.printf("%s%n", "Cisco Systems Inc."); | |
pw.printf("%s%n", "Research Triangle Park, Cary NC"); | |
pw.printf("%s%n", "27519"); | |
pw.close(); | |
Scanner in = new Scanner(Path.of(RW_FILE_PATH), StandardCharsets.UTF_8); | |
while(in.hasNextLine()) { | |
System.out.printf("%s%n", in.nextLine()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment