Advertisement
sindrijo

readFile

Dec 15th, 2011
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. package bleh;
  2.  
  3.  
  4. import java.io.File;      // IMPORTERE FILE
  5. import java.io.FileNotFoundException;
  6. import java.util.Scanner; // IMPORTERE SCANNER
  7.  
  8.  
  9.  
  10. public class readFile {
  11.  
  12.     public static void main(String[] args) {
  13.  
  14.         readFile("scoresheet.txt");
  15.        
  16.  
  17.     }
  18.    
  19.    
  20.     public static void readFile(String filename){
  21.        
  22.         File inputFile = new File(filename);
  23.         String buffer = "";
  24.        
  25.         try {
  26.             Scanner readFile = new Scanner(inputFile);
  27.            
  28.             while(readFile.hasNext()){
  29.                 buffer = readFile.nextLine();
  30.                 System.out.println(buffer);
  31.             }
  32.            
  33.         } catch (FileNotFoundException e) {
  34.             System.out.println("Cant find file.");
  35.         }
  36.        
  37.         System.out.println("Test.");
  38.        
  39.        
  40.        
  41.        
  42.     }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement