Solved

Iterate .xml files in a directory using Java/DOM4J

Posted on 2006-07-20
13
601 Views
Last Modified: 2012-05-05
I need to iterate .xml files in a directory, once I have a handle to the file I will get a read stream and do other things which I'm fine with - just need a quick and dirty way to iterate the files in the directory.  I'm using Java and DOM4J so if I can do it within those packages it would be great.

Thanks in advance.
pt_wood.
0
Comment
Question by:pt_wood
  • 4
  • 4
  • 3
  • +1
13 Comments
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 300 total points
Comment Utility
File dir = new File("somedir");
dir.listFiles(new FileFilter() {
    pubic boolean accept(File pathname) {
        return pathname.getName().toLowerCase().endsWith(".xml");
    }
});
0
 
LVL 37

Accepted Solution

by:
zzynx earned 200 total points
Comment Utility
CEHJ is right.
And in case you wouldn't know how to iterate:

File dir = new File("somedir");
File[] myFiles = dir.listFiles(new FileFilter() {
    public boolean accept(File pathname) {
        return pathname.getName().toLowerCase().endsWith(".xml");
    }
});
// Iterate through your files:
for (int i=0, m=myFiles.length; i<m; i++) {
   File theFile = myFiles[i];
   // Do with your file what you want...
}
0
 
LVL 10

Expert Comment

by:mukundha_expert
Comment Utility
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
:-)
0
 

Author Comment

by:pt_wood
Comment Utility
Thanks - i accepted CEHJ's reply - and zzynx's iteration tip helped and mukundha's link gives another approach if I get hung up.  -pt_wood.
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
>> zzynx's iteration tip helped
Then I wonder why I'm not part of a split
(And I also wonder what the comment should have been to deserve an A grade?)
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
pt_wood - if you want, we can get the question reopened so that zzynx is included
0
 

Author Comment

by:pt_wood
Comment Utility
ok can we do that - I couldn't figure out how to split the points - that's why I gave them all to CEHJ.

Also I'd like to change the grade to A also.

Thanks.
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
>> ok can we do that
I'll ask to reopen this Q.
Once reopened you can close it again using a split

>> I couldn't figure out how to split the points
Here's what EE's halp page says about that:

Can I split the points?
Yes. Scroll down to the bottom of the question, just above the text box, and click the "Split Points" link. Select the radio button of the comment who you want to Accept as the Accepted Answer. Only one button can be selected. Set the point value (a text box above the comment) of how much you want this person to receive of the points. Then set the point values for each of the experts comments to whom you want to allocate points and these will be considered Assisted Answers in helping you resolve the issue. Double check your information and then click the Submit button at the bottom of the page. One note: the total points of the splits must equal the amount you asked the question for itself, and no person can receive fewer than 20 points.
0
 

Author Comment

by:pt_wood
Comment Utility
I split 300/200 CEHJ/zzynx and changed grade to A.  Thank you.
0
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
Thanx 4 axxepting
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
:-)
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now