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
Solved

FileInputStreams

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to Alipay 10 43
Why doesn't this text field show up on my Applet frame? 2 19
hashmap order 17 37
Java class and jar 3 23
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
The viewer will learn how to implement Singleton Design Pattern in Java.

860 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