Solved

Iterate .xml files in a directory using Java/DOM4J

Posted on 2006-07-20
13
602 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

911 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

20 Experts available now in Live!

Get 1:1 Help Now