Created
December 3, 2013 22:07
-
-
Save tnhansel/7778397 to your computer and use it in GitHub Desktop.
Read data from .txt
This file contains 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
import java.util.Scanner; | |
public class ReadData | |
{ | |
public static void main(String[] args) throws Exception | |
{ | |
String message; // holding the line coming from the source | |
// creating the file class and giving its excat location | |
java.io.File x = new java.io.File("/Users/hanseltan/Documents/hello world.txt"); | |
// Create a Scanner named y to read the input stream from the file x | |
Scanner y = new Scanner(x); | |
// Reading the file | |
message = y.nextLine(); | |
// print the message from the file on the screen | |
System.out.println("reading from the data file...\n"); | |
System.out.println(message); | |
// closing connection | |
y.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
message = y.nextLine();
ini oke kalo misalnya dek dalem text file cuma ada satu line tapi kalo misalnya lebih dari satu line then line berikutnya ga kebaca.. kamu mesti taru ini dek dalem for loops.maybe this one better again i am not sure if
y.hasNext()
works.