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

    How do you read a directory structure from within an applet?



    If I have an applet running on a web page, how can I get this applet to read

    a directory (and then subsequent dirs) on the server, and then read the filenames

    and then display the filenames (or whatever)??


    is this possible?

  2. #2
    Join Date
    Mar 1999
    Posts
    9

    Re: How do you read a directory structure from within an applet?



    Hello Peter,


    Yes,you can do reading a directory.this can be done using

    recursive calls(possible there are other solutions too!).i tried to read

    dirs and files for my c:. it worked and the simple code is:

    File f = new File("C:");

    String[] flist;

    flist = f.list();

    the flist string array returns all the files and dirs of c:.next the dirs

    must be searched again and this will continue till there are no more dirs

    to search.hope this provides a start.ur feedback will be appreciated.


    best wishes

    thiru




  3. #3
    Join Date
    Mar 1999
    Posts
    2

    Re: How do you read a directory structure from within an applet?



    hmmm...


    can this be done in an applet?


    I have found some code to read a text file from the orginating host...but how can I

    read a directory???????


    try{

    URL url = new URL("http://somewhere.com/test.txt");

    // or URL url = new URL( getDocumentBase(), filename);

    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream() ) );

    String s = in.readLine(); //read till you get a null line.

    } catch(MalformedURLException e){

    System.out.println("URLException:"+e);

    } catch(IOException e){

    System.out.println("IOException:"+e);

    }




  4. #4
    Join Date
    May 1999
    Posts
    93

    Re: How do you read a directory structure from within an applet?



    Not without help from the server.


    Scenario 1: You could set up the web server to display the directory listing as

    a web page. Works only when you don't have any default page in that directory.

    You could read the webpage and parse it. Not recommended.


    Scenario 2: Install a CGI (or CGI like) script at the server. This script should

    serve up the content of the directory. You'd again have to load the page using

    HTTP and parse the result. Recommended.

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