Problem finding directory ** File dir = new File(URL+aFile_to_add);

Discussion in 'Java' started by vivienne wykes, Aug 3, 2004.

  1. Hi,

    Trying to read files from a dir on my site using a JSP and bean. I've tried
    nearly every option for the filepath I can think of and it doesn't seem to
    be finding the file...

    Here's the bit:

    String URL = "images\\wedding_photos\\";
    File dir = new File(URL+aFile_to_add);

    String[] files = dir.list();

    It's working locally, but I obviously had to change the path from c://... to
    the above.


    The full code is listed below in the addWedding Method

    The method removes the .jpg from the file name and then writes the new file
    name to a database
    Thanks for any insight.

    Regards

    Jim




    //**************************************************************************
    *********



    public String addWedding(String aFile_to_add)
    {
    String feedback = "unset in scrubWedding";
    try
    {

    String URL = "images\\wedding_photos\\";

    Class.forName("org.gjt.mm.mysql.Driver");
    java.sql.Connection connection =
    java.sql.DriverManager.getConnection("jdbc:mysql://localhost/rhwedd2_shop?us
    er=**********&password=*******");
    java.sql.Statement statement = connection.createStatement();
    File dir = new File(URL+aFile_to_add);
    String[] files = dir.list();

    if (files == null)
    {
    feedback = "Sorry, couldn't find the file "+aFile_to_add+"...no files have
    been added.";

    }
    else
    {
    for (int i=0; i<files.length; i++)
    {
    // Get filename of file or directory
    String filename = files;
    String no_extension;

    //convert string array element into a char array
    char [] charsfilename = filename.toCharArray();
    int newlength = charsfilename.length -4;
    no_extension = String.valueOf(charsfilename,0,newlength);
    filesAdded = filesAdded+", "+no_extension;
    // Show the new file names in stack trace without extension
    //System.out.println("String no_extension " + no_extension );

    statement.executeUpdate("INSERT INTO items VALUES
    ('"+no_extension+"',5,'"+aFile_to_add+"')");
    // write to table with item_id and weddingid
    feedback = "The following files have been added..."+filesAdded;
    }

    }

    if (statement != null )
    statement.close();

    if ( connection != null )
    connection.close();


    }
    catch(Exception e)
    {
    feedback = "Into the catch";
    e.printStackTrace(System.err) ;
    }

    return feedback;
    }//end addWedding


    //**************************************************************************
    *********
     
    vivienne wykes, Aug 3, 2004
    #1
    1. Advertising

  2. Andrew Thompson, Aug 3, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UnVkeQ==?=

    Sub Dir, Virtual dir, what do I use?

    =?Utf-8?B?UnVkeQ==?=, Jun 12, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    442
    =?Utf-8?B?UnVkeQ==?=
    Jun 12, 2005
  2. Matthew Denner
    Replies:
    1
    Views:
    211
  3. Kga Agk
    Replies:
    2
    Views:
    160
    Kga Agk
    Jun 29, 2009
  4. Nick Gnedin
    Replies:
    2
    Views:
    174
  5. MRAB
    Replies:
    0
    Views:
    132
Loading...

Share This Page