Advertisement
syad28

TRY FILE I/O

Nov 26th, 2015
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. package lab;
  2. import java.util.*;
  3. import java.io.*;
  4. public class Lab
  5. {
  6. public static void main(String[] args)
  7. {
  8. CUBA();
  9. }
  10. //METHOD TRY
  11. public static void CUBA(){
  12.    String dir = "D:/UNIVERSITI MALAYA/Software Engineering (WES150009)/Fundamental of Programming [WIX1002]/Data file for Assignment/login.txt";
  13.     try {
  14.        
  15.         PrintWriter text = new PrintWriter(new FileOutputStream(dir,true));
  16.         Scanner defaultText = new Scanner(new FileInputStream(dir));
  17.         text.close();
  18.         String teks;
  19.         while(defaultText.hasNextLine()){
  20.             teks=defaultText.nextLine();
  21.             System.out.println(teks);
  22.         }
  23.         //}
  24.        
  25.        
  26.         defaultText.close();
  27. //Closing index.html write ability
  28.        
  29.     }
  30.     catch(FileNotFoundException e){
  31.         System.out.println("File Not Found");
  32.     }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement