Click here to Skip to main content
15,905,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
i want get the all images from folder dynamically. Like i have to display gallery of a celebriti in my webpage by storing the folder path in Mysql database like galleryimages/(all images inside this folder) instead of storing all image paths in db. is there any way that i can access all images directly from folder instead of getting the path from db

is it possible if so how can i access these images from floder dynamically.

please help me.
Posted
Updated 19-Aug-13 1:33am
v2

What about the documentation ( "Filtering a Directory Listing By Using Globbing"[^])?
 
Share this answer
 
Comments
User-10031173 19-Aug-13 8:43am    
i have used the following method, am using netbeans IDE.
<pre>
public static List getImages(){
List l1=new ArrayList();
File dir = new File("../build/web/politicalimages");

// array of supported extensions (use a List if you prefer)
final String[] EXTENSIONS = new String[]{
"gif", "png", "jpg" // and other formats you need
};
// filter to identify images based on their extensions
FilenameFilter IMAGE_FILTER = new FilenameFilter() {
public boolean accept(final File dir, final String name) {
for (final String ext : EXTENSIONS) {
if (name.endsWith("." + ext)) {
return (true);
}
}
return (false);
}
};
if (dir.isDirectory()) { // make sure it's a directory
for (final File f : dir.listFiles(IMAGE_FILTER)) {
BufferedImage img = null;

try {
img = ImageIO.read(f);

// you probably want something more involved here
// to display in your UI
String imagepath= f.getName();
System.out.println("image path in dao class......."+imagepath);
l1.add(f);

}
catch (final IOException e) {
// handle errors here

}
}
}
return l1;
}
</pre>
but it returns null when i get the list values. how can i give netbeans folder path.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900