Solved

FileInputStreams

Posted on 2002-06-27
4
272 Views
Last Modified: 2010-03-31
I have a bunch of xml files in a directory. I do not know the names nor do I know the number of files.  How do I obtain FileInputStreams to each of these files.  i.e., Suck in all *.xml files in a given directory. Then create a FileInputStream for each.

How do I do this?  I need this to work on both Solaris and Windows..

Thanks
0
Comment
Question by:smithc
  • 3
4 Comments
 
LVL 19

Accepted Solution

by:
cheekycj earned 100 total points
ID: 7114703
you can get a listing of the files using this:

java.io.File dir = new java.io.File("/path/to/directory");
java.io.Files[] fileList;
int xmlfilecount = 0;
if (dir.isDirectory()) {
  java.io.File[] tempList = dir.listFiles();
  for(int i=0; i<tempList.length;i++) {
        if(!tempList [i].isDirectory()) {
          fileName = tempList [i].getName();
          if (fileName.toUpperCase().endsWith(".XML")) {
            fileList[xmlfilecount++] = (java.io.File) tempList[i].clone();
          }  
        }
  }
}

now you can iterate through the fileList array and create input streams for each one.

There is a way to deal with unix vs windoze file paths.. I will look into that.. but this should get you started.

CJ
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7114708
File.separatorChar is the what you can use to switch btw "/" and "\"

CJ
0
 

Author Comment

by:smithc
ID: 7114908
it works.  thanks!!  

having trouble deleting the other questions...can't seem to find a link anywhere to do this.  Even while editing the question.  any advice?
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7114919
post a 0 pt question in CS (Community Support) [link on the left]  Ask them to delete your dup questions.

I think deleting has been disabled for now.

Glad I could help out.  Thanx for the "A"

CJ
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
count11 challenge 6 47
nestparen challenge 4 56
Java and GPO 11 47
java 8 lambda expresssions exception handling 3 37
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

757 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

22 Experts available now in Live!

Get 1:1 Help Now