Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class LineCounter{
- private File file;
- public LineCounter(File file){
- this.file = file;
- }
- public void countLines(){
- int count = 0;
- try(Scanner scan = new Scanner(new BufferedReader(new FileReader(file)))){
- while(scan.hasNextLine()){
- count++;
- }
- }catch(Exception e){
- System.out.println("Nuk egziston file");
- }
- System.out.println("File i ka " + count + " rreshta");
- }
- public static void main(String[] args) throws Exception{
- File f = new File("test123.txt");
- if (!f.exists()){
- f.createNewFile();
- }
- System.out.println("123");
- LineCounter lc = new LineCounter(f);
- lc.countLines();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement