I am trying to read files from unix file system with a pattern format in a java program.
The file name pattern is like this:
"XYZ"+"abcd1234"+MMddyyyyHHmmss
For example: XYZabc123403222012101329
The middle pattern of "abcd1234" is not fixed but changes, so it will be alphanumeric and total character length of 7.
How can I read the file with such pattern? The file can contain text or serialized object.
String path="/tmp/somedir";
final File folder = new File("/tmp/somedir");
List<String> fileNames = new ArrayList<String>();
try {
for (final File fileEntry : folder.listFiles()) {
if (fileEntry.isDirectory()) {
listFilesForFolder(fileEntry);
} else {
//System.out.println(fileEntry.getName());
fileNames.add(fileEntry.getName());
}
}
for(String str: fileNames) {
FileInputStream fileIn = new FileInputStream(path+"/"+str);
}
} catch(FileNotFoundException e) {
e.printStackTrace();
} catch(Exception e1) {
e1.printStackTrace();
}
Thank You.