Solved

Iterate .xml files in a directory using Java/DOM4J

Posted on 2006-07-20
13
606 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
  • +1
13 Comments
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 300 total points
ID: 17146764
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
ID: 17146936
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
ID: 17146964
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 86

Expert Comment

by:CEHJ
ID: 17147184
:-)
0
 

Author Comment

by:pt_wood
ID: 17147212
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
ID: 17165619
>> 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
 
LVL 86

Expert Comment

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

Author Comment

by:pt_wood
ID: 17179966
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
ID: 17181692
>> 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
ID: 17188397
I split 300/200 CEHJ/zzynx and changed grade to A.  Thank you.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 17190445
Thanx 4 axxepting
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17190703
:-)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

628 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