Wednesday, 15 January 2014

file - How to display pictures from all subdirectories within a parent directory? (Java & Netbeans) -



file - How to display pictures from all subdirectories within a parent directory? (Java & Netbeans) -

i'm writing slideshow allows pictures shows deleted, edited or ignored displayed. it's working fine except when directory it's been pointed contains subfolders. in case code search through subfolders , display images within them. @ moment subfolders ignored , null pointer exception thrown, though images in main directory read , displayed. relevant section of code:

string files; file folder = new file(path); //loads folder file[] listoffiles = folder.listfiles(); //assigns filenames array (int = 0; < listoffiles.length; i++) { //some code here deals graphics random randomgenerator = new random(); //initiates random generator int randomint = randomgenerator.nextint(listoffiles.length); //limits max random lenth of folder array files = listoffiles[randomint].getname(); //chooses filename based on random number final string fileid = "file:///" + path + "\\" + files; //creates path display currentfile = path + "\\" + files; //assigns filename variable ready deletion later }

i need treat these more discrete images rather printing out list of them. i've excluded code here snippet deals painting screen (g.drawimage).

if suggests apache commons io fileutils, kind plenty explain how go downloading, installing , importing right libraries, i've been having problem achieving (if works). prefer solution doesn't require non-standard libraries. have read do-able in java 8 (which i'm using) i've not been able find relevant examples.

i apologise if turns out duplicate question, i've been unable find similar illustration quite matches these requirements. other examples seem content list files, rather perform action them.

many in advance.

java file netbeans graphics folders

No comments:

Post a Comment