Click here to Skip to main content
15,908,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to count the number of PDF files present in a folder using Java. How can I do this?
Posted
Updated 24-Aug-10 8:29am
v2
Comments
Sandeep Mewara 24-Aug-10 12:05pm    
Did you tried anything yourself?

How about something like:
Java
import java.io.*;

class JustATest
{
    public class PdfFileFilter implements FileFilter
    {
        public boolean accept(File pathname)
        {
            if (pathname.getName().toLowerCase().endsWith(".pdf")) return true;
            return false;
        }
    }

    public static void main(String args[])
    {
        File dir = new File("Your_directory_here");
        System.out.println("Number of PDF files: " + dir.listFiles(new PdfFileFilter()).length);
    }
}


I didn't try it, but at least it could give you an idea. :)
 
Share this answer
 
v2
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900