java - Listing only files in directory -


i have folder following structure

c:/rootdir/  rootdir has following files  test1.xml test2.xml test3.xml testdirectory <------- subdirectory inside rootdir 

i'm interested in xml files inside rootdir. cuz if use jdom read xml following code considers files inside "testdirectory" , spits out "content not allowed exception"

file testdirectory = new file("c://rootdir//"); file[] files = testdirectory.listfiles(); 

how can exclude subdirectory while using listfiles method? following code work?

file testdirectory = new file("c://rootdir//"); file[] files = testdirectory.listfiles(new filenamefilter() {      @override     public boolean accept(file dir, string name) {         return name.tolowercase().endswith(".xml");     } }); 

use filefilter instead, give access actual file, include check file#isfile

file testdirectory = new file("c://rootdir//"); file[] files = testdirectory.listfiles(new filefilter() {     @override     public boolean accept(file pathname) {         string name = pathname.getname().tolowercase();         return name.endswith(".xml") && pathname.isfile();     } }); 

Comments