ariestamirra

readfile

May 25th, 2014
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.File;
  3. import java.io.FileNotFoundException;
  4. import java.io.FileReader;
  5. import java.io.IOException;
  6.  
  7. /**
  8.  *
  9.  * @author Mirra Ariesta
  10.  */
  11. public class ReadFile {
  12.  
  13.     public static void m() throws FileNotFoundException, IOException {
  14.         File file = new File("Data.txt");
  15.         BufferedReader fileReader;
  16.         fileReader = new BufferedReader(new FileReader(file));
  17.         while (true) {
  18.             String line = fileReader.readLine();
  19.             if (line == null) {
  20.                 break;
  21.             }
  22.             System.out.println(line);
  23.         }
  24.     }
  25.  
  26.     public static void main(String args[]) {
  27.         try {
  28.             m();
  29.         } catch (FileNotFoundException ex) {
  30.             System.out.println("File tidak ada");
  31.         } catch (IOException ex) {
  32.             System.out.println("Error IO Exception");
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment