Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to read a file

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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";
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Politics is a circus designed to distract you from what is really going on. So is this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic