-
September 19th, 2011, 01:25 AM
#1
how to search a file in a network
hi all
i am new to java..i want to search a file in the network...i have developed the code if i enter the file name to be searched it searches only on the particular system..but i need to search the file when two systems are connected through remote log on...eventhough the file to be searched is in shared folder itz not searching..please suggest me some ideas..here is my code
import java.io.*;
import java.util.Scanner;
public class Searcher
{
static boolean foundFlag;
static String search(File dir,String fname)
{
if(dir.isDirectory())
{
String children[]=dir.list();
if(children!=null)
{
for(String child:children)
{
File c=new File(dir.getPath()+"\\"+child);
if(c!=null && c.canRead())
{
String path=search(c,fname);
if(!path.equals(""))
{
foundFlag=true;
System.out.println(path);
}
}
}
}
}
if(dir.isFile())
{
if(fname.equals(dir.getName()))
return (dir.getPath()+"\n");
}
return "";
}
public static void main(String args[])throws IOException
{
String filename,drive;
BufferedReader s=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the File Name:");
filename=s.readLine();
File [] d=new File("").listRoots();
for(int j=0;j<d.length;j++)
{
drive=d[j].toString();
File dir=new File(drive);
String path=search(new File(drive),filename);
if(!path.equals(""))
{
foundFlag=true;
System.out.println(path);
}
}
if(foundFlag==false)
{
System.out.println("File not found.");
}
}
}
-
September 19th, 2011, 07:33 AM
#2
Re: how to search a file in a network
Where is the file located that you want to read?
Do you have the full and correct path to the file?
What is the "network" you are searching on?
What OS is defining this "network"?
Norm
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|