by Dinesh Thakur Category: Stream



class CountingLinesJavaExample
         public static void main(String args[]) throws IOException
             String t;
             int l,w,c,n,i;
             BufferedReader fin = new BufferedReader(new FileReader(args[0]));
                             t= fin.readLine();
                             if (t==null)
                             n = t.length();
                             for (i=0;i<=n-1;i++)
                                     if(t.charAt(i)==' ')w++;
                                    catch(IOException e){}
                System.out.println("The Number of lines are "+l);
                System.out.println("The Number of lines are "+w);
                System.out.println("The total number of characters are"+c);

Counting Lines,words,Char in a File Java Example

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Search Content

Popular Article