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
//**************************************************************************
*********
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
//**************************************************************************
*********