Solved

FileInputStreams

Posted on 2002-06-27
4
289 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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 will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

808 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