Solved

FileInputStreams

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
swing controls 2 35
jsp error 6 67
How to overcome error: The method of type x must override y or implement a supertype method 4 30
Session in java desktop 5 34
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 …
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 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…
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

738 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