Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Iterate .xml files in a directory using Java/DOM4J

Posted on 2006-07-20
13
Medium Priority
?
613 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 1200 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 800 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

963 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