Skip to content

Instantly share code, notes, and snippets.

@erikgunawan
Created October 22, 2014 03:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikgunawan/56dce18ba33d2dd4d027 to your computer and use it in GitHub Desktop.
Save erikgunawan/56dce18ba33d2dd4d027 to your computer and use it in GitHub Desktop.
Membaca File *.txt Menggunakan Scanner dengan Java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
/**
* @Developer : Erik Gunawan
* @Nickname : EXz
* @Phone : 0896 5332 0577
* @EMail : admin@erikgunawan.com
* @Gmail : erik.gunawan44@gmail.com
* @Website : www.erikgunawan.com
* @Facebook : facebook.com/revolutionist.exz
* @Twitter : twitter.com/_EXz
*/
public class BacaTextFile {
public static void main(String[] args) {
String lokasi_file = "D:/BacaText/data.txt";
try {
File f = new File(lokasi_file);
Scanner s = new Scanner(f);
while(s.hasNextLine()){
String text = s.nextLine();
System.out.println(text);
}
}
catch (FileNotFoundException fnfe) {
fnfe.getMessage();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment