uni

University stuff
git clone git://git.christosmarg.xyz/uni-assignments.git
Log | Files | Refs | README | LICENSE

ReadLines.java (655B)


      1 import java.io.*;
      2 
      3 class ReadLines {
      4 	public static void main(String args[]) {
      5 		BufferedReader br;
      6 		File f;
      7 		String str;
      8 		int ln = 0;
      9 
     10 		try {
     11 			f = new File(args[0]);
     12 			br = new BufferedReader(new FileReader(f));
     13 
     14 			while ((str = br.readLine()) != null) {
     15 				System.out.println(str);
     16 				ln++;
     17 			}
     18 			br.close();
     19 		} catch (FileNotFoundException e) {
     20 			System.err.println("file not found");
     21 			return;
     22 		} catch (IOException e) {
     23 			System.err.println("IO Exception");
     24 			return;
     25 		} catch (ArrayIndexOutOfBoundsException e) {
     26 			System.err.println("usage: java ReadLines file");
     27 			return;
     28 		}
     29 
     30 		System.out.println("Lines read: " + ln);
     31 	}
     32 }