Code to read a file and get the file with a certain pattern


package edu.scjp.regex;

import java.io.*;
import java.util.regex.*;
import java.util.Calendar;
import java.util.GregorianCalendar;

public class FindFiles {
     
      @SuppressWarnings("deprecation")
      public static void main(String args[]){
           
            // variable to hold the file data
            String data = null;
            String[] line = null;
           
            Calendar cal = new GregorianCalendar();
           
            int currentYear =  cal.get(Calendar.YEAR);
          int currentDate =  cal.get(Calendar.DATE);
            int currentMonth = cal.get(Calendar.MONTH);
           
            //String sCurrentDate = currentDate.t
            String currentDateFormat_1 = Integer.toString(currentMonth)+ Integer.toString(currentDate)+ Integer.toString(currentYear);
            String currentDateFormat_2 = Integer.toString(currentYear)+ Integer.toString(currentMonth)+ Integer.toString(currentDate);
           
            System.out.println(currentDateFormat_1);
            System.out.println(currentDateFormat_2);
           
            try {
                  // create a file reader handle
                  FileReader fileReader = new FileReader("C:\\view\\test.txt");
                 
                  BufferedReader bufferedReader = new BufferedReader(fileReader);
                 
                  while((data = bufferedReader.readLine())!= null)
                  {
                        line = data.split(",");
                       
                        for (int i = 0 ; i < line.length; i++)
                        {
                              Pattern pattern_1 = Pattern.compile("CTRAX_NL_SCAN_Roanoke_"+currentDateFormat_1);
                              Pattern pattern_2 = Pattern.compile("NEW_FORMATTED_ROANOKE_"+currentDateFormat_2);
                              Pattern pattern_3 = Pattern.compile("PAID_FORMATTED_ROANOKE_"+currentDateFormat_2);
                             
                              Matcher     matcher_1 = pattern_1.matcher(line[i]);
                              Matcher     matcher_2 = pattern_2.matcher(line[i]);
                              Matcher     matcher_3 = pattern_3.matcher(line[i]);
                       
                       
                        while(matcher_1.find())
                        {
                              System.out.println(line[i]);
                        }
                       
                        while(matcher_2.find())
                        {
                              System.out.println(line[i]);
                        }
                       
                        while(matcher_3.find())
                        {
                              System.out.println(line[i]);
                        }
                  }
                  }    
                 
                  }catch(IOException ioe) {
                  ioe.printStackTrace();
            }
     
      }
}


Code to Convert Date into dd/mm/yyyy Format


package com.prokarma.calendar;

import java.util.Calendar;
import java.util.GregorianCalendar;

public class CalendarString {
     
      public static void main(String[] args) {

      Calendar cal = new GregorianCalendar();
      String date = "";
      String month = "";
     
      int year = cal.get(Calendar.YEAR);
      int month_1 = cal.get(Calendar.MONTH);
      int date_1 = cal.get(Calendar.DATE);
     
      if ( date_1 < 10 )
            date = "0" + date_1;
      else
            date = Integer.toString(date_1);
      if ( month_1 < 10 )
            month = "0" + month_1;
      else
            month = Integer.toString(month_1);

      String currentDate =  date + "/" + month + "/" + year ;
     
      System.out.println("Current Date(dd/mm/yyyy): " + currentDate);

   }

}

Charts with YUI3


src="http://yui.yahooapis.com/3.4.1/build/yui/yui-min.js"></script>