TechFundu

  • Increase font size
  • Default font size
  • Decrease font size
Welcome Guest,  Login | Join Now
Home Forum

Directory search for a file in java
(1 viewing) (1) Guest
Java Fundamentals discussion forum.
Go to bottomPage: 1
TOPIC: Directory search for a file in java
#70
Directory search for a file in java 2 Years, 4 Months ago Karma: 0
Hi All,

I am trying to write a java program for a particular file search in a local directory. Could anyone please help me out with this?

Thanks in advance.
shobha
Fresh Boarder
Posts: 3
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#71
Re:Directory search for a file in java 2 Years, 4 Months ago Karma: 0
A directory is referred as file in Java.There are several classes in java.io.File for searching and manipulating directories.
Have a look on the below program. Hope this will help you.

public static void main(String[] args) {

String files =null;
File filesDir = new File("C:/Files");
String strfilename = "Abc";
if(filesDir.isDirectory()){
String filenames[] = filesDir.list();
for(int i=0; i<filenames.length; i++)
{
if(filenames[i].startsWith(strfilename)){
files = filenames[i];
System.out.println(" Files in dir are---" + files);
}
}

}
}

This program will give you all the file names starting with Abc. You can modify it as per your needs.
deepa
Fresh Boarder
Posts: 5
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#72
Re:Directory search for a file in java 2 Years, 4 Months ago Karma: 0
Thanks for your prompt reply. It helped me a lot.
shobha
Fresh Boarder
Posts: 3
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
Go to topPage: 1
get the latest posts directly to your desktop
Follow us on Twitter