Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | None | 0 0
  1. Public class CountLines(){
  2.     try{
  3.         BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
  4.         System.out.println("Vennligst skriv inn filnavnet og -pathen du vil lagre infoen i:");
  5.         String str = bf.readLine();
  6.         File fil = new File(str);
  7.         if (fil.exists()){
  8.             FileReader fr = new FileReader(fil);
  9.             LineNumberReader ln = new LineNumberReader(fr);
  10.             int antall = 0;
  11.             while (ln.readLine() != null){
  12.                 antall++;
  13.             }
  14.             return antall;
  15.         }
  16.         else{
  17.             System.out.println("File does not exists!");
  18.         }
  19.     }
  20.     catch(IOException e){
  21.         e.printStackTrace();
  22.     }
  23.    
  24. }
  25. ID=CountLines();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement