In this example we will show the method to find files with certain extension in Java.
Source Code
package com.beginner.examples;
import java.io.*;
public class FileOperator10Example {
public static void main(String[] args )
{
File path = new File("example");
File file = null;
File[] filelist = path.listFiles();
for (int i = 0; i < filelist.length; i++)
{
file = filelist[i];
if (file.getName().endsWith(".txt"))
{
System.out.println(file + " is found.");
}
}
}
}
Output:
exampletest.txt is found.