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

V

vivienne wykes

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


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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top