Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

FileInputStreams

Posted on 2002-06-27
4
Medium Priority
?
314 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
[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
  • 3
4 Comments
 
LVL 19

Accepted Solution

by:
cheekycj earned 400 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

610 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