program to find a perticular string in a file using java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gauravkhanna
    New Member
    • Sep 2006
    • 5

    program to find a perticular string in a file using java

    import java.io.*;

    class Automation1 implements Runnable
    {
    int iterationCount= 0;
    Thread t;
    FileReader fr;
    //FileWriter fw;
    BufferedReader br;
    //BufferedWriter bw;

    public Automation1()
    {
    t = new Thread(this,"Ne w Thread");
    t.start();
    }

    public static void main(String args[])
    {
    new Automation1();
    }

    public void func()
    {
    int i,x=0;
    i=1;
    boolean ifFound = false;
    String str="" , append="";
    try
    {
    //fw = new FileWriter("C:/Gaurav/Java_Classes/output.doc");
    fr = new FileReader("C:/Documents and Settings/Administrator/Desktop/exprep.log");
    br = new BufferedReader( fr);
    //bw = new BufferedWriter( fw);
    while((append = br.readLine()) != null)
    { //str=str+append;
    x=append.toLowe rCase().indexOf ("verified successfully.") ;
    //System.out.prin tln("I am here only");
    if(x >= 0)
    {
    //System.out.prin tln("I am finally inside if loop");
    System.out.prin tln("Export Process Successful");
    ifFound = true;
    break;
    }
    i++;
    }

    //bw.write(str2);
    //System.out.prin tln(str2);
    //System.out.prin tln(str.substri ng(0,10));
    System.out.prin tln("Value of x is :"+ x);
    //System.out.prin tln("Value of y is :"+ y);
    if(!ifFound)
    System.out.prin tln("Export process failed");
    fr.close();
    br.close();
    }
    catch(StringInd exOutOfBoundsEx ception s) {}
    catch(FileNotFo undException ae) {}
    catch(NullPoint erException npe) {}
    catch(IOExcepti on e)
    {
    System.out.prin tln(e);
    }
    System.out.prin tln(i);
    iterationCount+ +;
    }
    public void run()
    {
    while(iteration Count != 1)
    {
    try
    {
    func();
    Thread.sleep(10 );
    }
    catch (InterruptedExc eption ie)
    {
    System.out.prin tln(ie);
    }
    }
    }
    };

    I am trying to find the string "verified successfully" in a log file using the above program.... but i am not able to do that. can someone please suggest what i need to do....


    can anyone send me the code please its really urgent
    i am struggling with this
    quick response will be highly appreciated

    In my next post i will be pasting the log file
  • gauravkhanna
    New Member
    • Sep 2006
    • 5

    #2
    log file

    Connecting to the database...
    Connected.
    Making 2nd connection to exported datasource: SiebSrvr_IBMLAB ES...
    Connected.
    Starting common api.

    Exporting Tables
    Exporting table S_ACCELERATOR ... exported 154 rows
    Exporting table S_ACCELRTR_INTL ... exported 154 rows
    S_DOCK_REL_DOBJ ... exported 10 rows
    Exporting table S_DOCK_TABLE ... exported 1868 rows
    S_PVIEW_REPORT ... exported 0 rows
    Exporting table S_PVW_RPT_INTL ... exported 0 rows
    Exporting table S_PVW_WEB_TMPL ... exported 0 rows
    Exporting table S_PVW_WTI_INTL ... exported 0 rows
    Exporting table S_PVW_WTMPL_IT ... exported 0 rows
    Exporting table S_REPORT ... exported 210 rows
    Exporting table S_REPORT_FIELD ... exported 2472 rows
    Exporting table S_REPORT_INTL ... exported 207 rows
    Exporting table S_SCHMPROC_DBMS ... exported 157 rows
    Exporting table S_SCHMSTEP_SCPT ... exported 1339 rows
    Exporting table S_SCHMST_DBSCPT ... exported 2010 rows
    Exporting table S_SCHM_PHASE ... exported 139 rows
    Exporting table S_SCHM_PHS_USG ... exported 1665 rows
    Exporting table S_SCHM_PROC ... exported 71 rows
    Exporting table S_SCHM_PROC_VAR ... exported 1633 rows
    Exporting table S_SCHM_STEP ... exported 988 rows
    Exporting table S_SCHM_STEP_DEP ... exported 0 rows
    Exporting table S_SCREEN ... exported 489 rows
    Exporting table S_SCREEN_INTL ... exported 454 rows
    Exporting table S_SCREEN_VIEW ... exported 4861 rows
    Exporting table S_SCR_MENU_ITEM ... exported 1579 rows
    Exporting table S_SCR_MITM_INTL ... exported 1359 rows
    Exporting table S_SCR_VIEW_INTL ... exported 4378 rows
    Exporting table S_SERVICE ... exported 470 rows
    Exporting table S_SERVICE_INTL ... exported 455 rows
    Exporting table S_SERVICE_METH ... exported 1441 rows
    Exporting table S_SERVICE_M_ARG ... exported 4167 rows
    Exporting table S_SERVICE_SBSYS ... exported 45 rows
    Exporting table S_SERVICE_SCRPT ... exported 388 rows
    Exporting table S_SERVICE_UPROP ... exported 1602 rows
    Exporting table S_SRCHENG_FIELD ... exported 95 rows
    Exporting table S_SRCHENG_PVIEW ... exported 22 rows
    Exporting table S_SRCHENG_TABLE ... exported 30 rows
    Exporting table S_SRCH_CAT ... exported 27 rows
    Exporting table S_SRCH_CRF_INTL ... exported 52 rows
    Exporting table S_SRCH_CTRESFLD ... exported 79 rows
    Exporting table S_SRCH_DCT_INTL ... exported 70 rows
    Exporting table S_SRCH_DEF ... exported 13 rows
    Exporting table S_SRCH_DEF_CAT ... exported 70 rows
    Exporting table S_SRCH_ENG ... exported 1 rows
    Exporting table S_SRCH_FILTRFLD ... exported 31 rows
    Exporting table S_SRCH_FLD_INTL ... exported 95 rows
    Exporting table S_SRCH_INDEX ... exported 20 rows
    Exporting table S_SRCH_INDX_FLD ... exported 121 rows
    Exporting table S_SRCH_PICKVIEW ... exported 17 rows
    Exporting table S_SRCH_RESULFLD ... exported 19 rows
    Exporting table S_SRCH_TABLE ... exported 20 rows
    Exporting table S_SRCH_TBL_INTL ... exported 30 rows
    Exporting table S_SRCH_VIS_VIEW ... exported 3 rows
    Exporting table S_STRING ... exported 0 rows
    Exporting table S_STRING_MAP ... exported 0 rows
    Exporting table S_SUB_REPORT ... exported 306 rows
    Exporting table S_SUB_REPORT_FL D ... exported 2289 rows
    Exporting table S_SVC_BRS_SCRPT ... exported 0 rows
    Exporting table S_SVC_MARG_INTL ... exported 3199 rows
    Exporting table S_SVC_METH_INTL ... exported 1348 rows
    Exporting table S_SVR_COMP ... exported 142 rows
    Exporting table S_SVR_COMP_SUBS ... exported 593 rows
    Exporting table S_SVR_EVT_SUBTY ... exported 464 rows
    Exporting table S_SVR_EVT_TYPE ... exported 181 rows
    Exporting table S_SVR_PARAM ... exported 1082 rows
    Exporting table S_SVR_STAT ... exported 50 rows
    Exporting table S_SVR_SVAL ... exported 81 rows
    Exporting table S_SYSACT_OBJECT ... exported 19 rows
    Exporting table S_TABLE ... exported 2753 rows
    Exporting table S_TBAR_ITM_INTL ... exported 27 rows
    Exporting table S_TBL_NT_PARAMS ... exported 0 rows
    Exporting table S_TEXT_STYLE ... exported 0 rows
    Exporting table S_TOOLBAR ... exported 21 rows
    Exporting table S_TOOLBAR_INTL ... exported 20 rows
    Exporting table S_TOOLBAR_ITEM ... exported 160 rows
    Exporting table S_TREE ... exported 95 rows
    Exporting table S_TREE_ND_INTL ... exported 316 rows
    Exporting table S_TREE_NODE ... exported 319 rows
    Exporting table S_UKA_TREE_NODE ... exported 0 rows
    Exporting table S_UK_ATTJOIN ... exported 38250 rows
    Exporting table S_USER_KEY ... exported 2888 rows
    Exporting table S_USER_KEY_ATT ... exported 14487 rows
    Exporting table S_USER_KEY_COL ... exported 6816 rows
    Exporting table S_VIEW ... exported 3897 rows
    Exporting table S_VIEW_INTL ... exported 3808 rows
    Exporting table S_VIEW_LAYOUT ... exported 0 rows
    Exporting table S_VIEW_REPORT ... exported 2112 rows
    Exporting table S_VIEW_RPT_INTL ... exported 1774 rows
    Exporting table S_VIEW_WEB_TMPL ... exported 3564 rows
    Exporting table S_VIEW_WTI_INTL ... exported 144 rows
    Exporting table S_VIEW_WTMPL_IT ... exported 8059 rows
    Exporting table S_WEBPG_IT_INTL ... exported 251 rows
    Exporting table S_WEB_PG ... exported 54 rows
    Exporting table S_WEB_PG_ITM ... exported 257 rows
    Exporting table S_WEB_PG_IT_PRM ... exported 101 rows
    Exporting table S_WEB_TMPL ... exported 356 rows
    Exporting table S_WEB_TMPL_FILE ... exported 356 rows

    TOTAL TABLES: 266
    TOTAL ROWS : 3437
    Verifying...
    Verified successfully.
    Cleaning up, disconnecting from the database.
    Elapsed time: 7 min 32 sec.

    Comment

    • Niheel
      Recognized Expert Moderator Top Contributor
      • Jul 2005
      • 2432

      #3
      Merged your threads. Please keep related posts in one thread instead of posting multiple threads.
      niheel @ bytes

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        1. Use code tags when posting your code
        2. Why are using a thread to do this?
        3. What is happening when you run the program? What is the error?

        Comment

        • gauravkhanna
          New Member
          • Sep 2006
          • 5

          #5
          Originally posted by r035198x
          1. Use code tags when posting your code
          2. Why are using a thread to do this?
          3. What is happening when you run the program? What is the error?


          Act you must have gone through the log file. In the log file there one string at the end ie "verified successfully".
          But through my code its not able to find that string
          what output its giving to me is as follow:

          Value of x is :-1
          Export process failed
          282

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by gauravkhanna
            Act you must have gone through the log file. In the log file there one string at the end ie "verified successfully".
            But through my code its not able to find that string
            what output its giving to me is as follow:

            Value of x is :-1
            Export process failed
            282
            I have copied your log file into a text file and the program worked correctly(found the string.) You are probably reading the wrong file.

            Comment

            • seenathinks
              New Member
              • Sep 2007
              • 1

              #7
              Hi ... gaurav khanna .... what is the purpose of threads here in your code to search for a string in the log file .... can u please explain this? and can we do this without using the threads....if u know please send that code ...

              Comment

              Working...