Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2013
    Posts
    5
    Rep Power
    0

    Default Display the list of files from a directory and obtain its output in index html format

    I need display a list of files(csv files) from a directory and generate its output in html using PrintWriter of java Io
    The index page should be look like 1. Filename( from directory and it should be hyperlink.)
    2. 2nd filename
    3. 3rd filename etc
    Please provide the java code the same.

    please help m ASAP.


    Thanks in advance

    Regards,
    Noor

  2. #2
    Join Date
    Jul 2013
    Posts
    5
    Rep Power
    0

    Default Re: Display the list of files from a directory and obtain its output in index html fo

    Please friends i am looking forward for your response i need to complete this task by today,please help.

  3. #3
    Join Date
    Jul 2013
    Posts
    5
    Rep Power
    0

    Default Re: Display the list of files from a directory and obtain its output in index html fo

    import java.io.File;

    import java.io.FileNotFoundException;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.io.StringWriter;
    import java.util.ArrayList;


    public class NewIndex {

    private static ArrayList<File> Process(File file)throws FileNotFoundException, IOException {
    // Look up the contents of the directory

    ArrayList<File> listAr = new ArrayList<File>();


    File[] files = file.listFiles();

    // Set up an output stream we can print the table to.
    // This is easier than concatenating strings all the time.


    StringWriter sout = new StringWriter();

    PrintWriter out = new PrintWriter(sout);

    // Print the directory name as the page title
    out.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
    out.println("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
    out.println("<head><meta http-equiv=\"Content-type\" content=\"text/html;charset=UTF-8\"/>");
    out.println("<title> Report</title>");
    out.println("<style type=\"text/css\">");
    out.println("body{background-color:#FFF;color:#000;font-family:OpenSans,sans-serif;font-size:10px;}");
    out.println("table{border:0.2em solid #2F6FAB;border-collaoute:collaoute;}");
    out.println("th{border:0.15em solid #2F6FAB;padding:0.5em;background-color:#E9E9E9;}");
    out.println("td{border:0.1em solid #2F6FAB;padding:0.5em;background-color:#F9F9F9;}</style>");
    out.println("</head><body><h1>" + file + ".html" + "</h1>");

    // Print out the table
    out.println("<table");
    out.println("<th>SL-No</th><th>List</th>");


    for (int index = 0; index <files.length; index++)
    { listAr.add(files[index]);
    //File f = new File(file, files[index]);

    out.println("<tr><td>" +
    (file.isDirectory() ?
    "<a href=\""+file+"\">" + files[index] + "</a>" :
    files[index]) +

    "</td></tr>");
    }
    out.println("</table>");

    String strOut ="OutputFolder name"
    FileWriter fw = new FileWriter(strOut);

    fw.close();
    return listAr;

    }




    public static void main(String[] args) {


    try {String dirname = "InputDirectory";
    File file = new File(dirname);
    Process(file);
    } catch (FileNotFoundException fileNotFoundException) {
    fileNotFoundException.printStackTrace();
    } catch (IOException ioException) {
    ioException.printStackTrace();
    }


    }
    }

  4. #4
    Join Date
    Jul 2013
    Posts
    5
    Rep Power
    0

    Default Re: Display the list of files from a directory and obtain its output in index html fo

    Not able to get the output please help friends

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,406
    Rep Power
    20

    Default Re: Display the list of files from a directory and obtain its output in index html fo

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    Join Date
    Jul 2013
    Posts
    5
    Rep Power
    0

    Default Re: Display the list of files from a directory and obtain its output in index html fo

    Hmmmmm

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,406
    Rep Power
    20

    Default Re: Display the list of files from a directory and obtain its output in index html fo

    Quote Originally Posted by unsaqa@gmail.com View Post
    Hmmmmm
    Boo!
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,086
    Rep Power
    20

    Default Re: Display the list of files from a directory and obtain its output in index html fo

    Quote Originally Posted by unsaqa@gmail.com View Post
    Not able to get the output please help friends
    What does that code do?
    What should it do?
    Do you get any exceptions?
    If so then post the full exception including stack trace, highlighting the line in your code it is thrown from.
    After you have added code tags to your code so it's actually readable.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Get directory files list as a stream
    By Dijkstra in forum Advanced Java
    Replies: 4
    Last Post: 05-04-2012, 12:26 PM
  2. Populating a gui list box with the files in a directory
    By josejvelezcolon in forum New To Java
    Replies: 1
    Last Post: 08-10-2009, 04:50 PM
  3. output for list of names in a format
    By Ms.Ranjan in forum New To Java
    Replies: 7
    Last Post: 06-18-2009, 04:47 PM
  4. how to list certain files in a given directory in java
    By corpusluteum in forum New To Java
    Replies: 6
    Last Post: 09-24-2008, 12:19 AM
  5. How can I get list of files in a directory
    By karma in forum New To Java
    Replies: 2
    Last Post: 12-14-2007, 11:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •