CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2011
    Posts
    3

    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.");
    }
    }
    }

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    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
  •  





Click Here to Expand Forum to Full Width

Featured