• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to read a file  RSS feed

 
bob morkos
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the format that I want to read "YYYYMMDD_HHMMSS_FV.BPO", However I only know the Date Format YYYYMMDD and I have no clue "HHMMSS". Is there a way, to read the above format by using a wild card or something?

Calendar c = Calendar.getInstance();
c.setTime(this.processDate);
int month = c.get(Calendar.MONTH) + 1;
String sMonth = null;
if (month < 10) {
sMonth = "0" + month;
} else {
sMonth = Integer.toString(month);
}
int days = c.get(Calendar.DAY_OF_MONTH);
String sDays = null;
if (days < 10) {
sDays = "0" + days;
} else {
sDays = Integer.toString(days);
}
int years = c.get(Calendar.YEAR);
String sYears = Integer.toString(years);

String dateFormatStr = sYears + sMonth + sDays;
String fileName = dateFormatStr + "_" + * + "_" + "FV.BPO";
 
Joe Ess
Bartender
Posts: 9440
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, you may find it easier to use java.text.SimpleDateFormat to construct you filename. When given the choice between reinventing the wheel and using something in the API, use the API. It's been tested far more thourghly than any homebrew code.
Next, java.io.File provides several methods to get find files, several of which take an argument of java.io.FilenameFilter. FilenameFilter is an interface, so you will have to implement it on your own, but it should be pretty simple. Your implementation of FilenameFilter would return true from accept() if the given file name exists, is a file and starts with the formatted date you are looking for.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!