- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to find the file using Java?
Following example shows the way to look for a particular file in a directory by creating a File filter. Following example displays all the files having file names beginning with 'b'.
Example
import java.io.*; public class Main { public static void main(String[] args) { File dir = new File("C:"); FilenameFilter filter = new FilenameFilter() { public boolean accept (File dir, String name) { return name.startsWith("b"); } }; String[] children = dir.list(filter); if (children == null) { System.out.println("Either dir does not exist or is not a directory"); } else { for (int i=0; i< children.length; i++) { String filename = children[i]; System.out.println(filename); } } } }
Output
build build.xml
- Related Articles
- How to find the file using C#?
- How to find a file using Python?
- How to check the Existence of a File using Java?
- How to Find Hash of File using Python?
- How to read the contents of a JSON file using Java?
- How to create Directories using the File utility methods in Java?
- How to Write/create a JSON file using Java?
- How to find the Strings within a text file in Java?
- How to store the contents of arrays in a file using Java?
- How to add/append content to an existing file using Java?
- How to get only the file name using find command on Linux?
- How to find the file modified after a certain date using PowerShell?
- How to Find the Shortest Words in a Text File using Python?
- How to Find the Longest Words in a Text File using Python?
- How to write a JSON string to file using the Gson library in Java?

Advertisements