View Single Post
Old 10-28-2004, 04:16 AM   #1 (permalink)
philthee
Registered User
 
Join Date: Oct 2004
Posts: 15
philthee is on a distinguished road
reading files from a directory and printing

Hi there,

can someine give me a hand with the above problem.
I have code here that can read a file from a given path but i would like to be able to read a directory from a given path and do something with the file names.
The file names are of type catA1.cyt, catA1.jpg, catA2.cyt, catA2.jpg etc..

i want to split up the filenames (only interested in the .cyt ones) and keep the A1, A2 etc to put them somewhere.

[code]

/*
* splitString.java
*
* Created on 28 October 2004, 13:05
*/

package Strings;
import java.io.*;
import java.util.*;

/**
*
* @author devallp
*/
public class splitString {

/** Creates a new instance of splitString */
public splitString() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
String path = "/mnt/rinetapp1a/users/devallp/src/demoChromosomeStuff
/cat/catA1.cyt";
File catFile = new File(path);
FileInputStream stuff = new FileInputStream(catFile);
FileReader fr = new FileReader(catFile);
BufferedReader in = new BufferedReader(fr);
String line;


while ((line = in.readLine()) != null) {

System.out.println(line);


}
}

catch (FileNotFoundException e) {
System.out.println("File disappeared");
}

catch (java.io.IOException e) {
System.out.println("hmmmmm??");
}
// TODO code application logic here
}

}
[\code]


so this reads a file from a path and prints out the contents.
what would i do firstly to read a directory and print the contents?

Last edited by philthee; 10-28-2004 at 05:51 AM.
philthee is offline   Reply With Quote