473,395 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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,"New 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.toLowerCase().indexOf("verified successfully.");
//System.out.println("I am here only");
if(x >= 0)
{
//System.out.println("I am finally inside if loop");
System.out.println("Export Process Successful");
ifFound = true;
break;
}
i++;
}

//bw.write(str2);
//System.out.println(str2);
//System.out.println(str.substring(0,10));
System.out.println("Value of x is :"+ x);
//System.out.println("Value of y is :"+ y);
if(!ifFound)
System.out.println("Export process failed");
fr.close();
br.close();
}
catch(StringIndexOutOfBoundsException s) {}
catch(FileNotFoundException ae) {}
catch(NullPointerException npe) {}
catch(IOException e)
{
System.out.println(e);
}
System.out.println(i);
iterationCount++;
}
public void run()
{
while(iterationCount != 1)
{
try
{
func();
Thread.sleep(10);
}
catch (InterruptedException ie)
{
System.out.println(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
Oct 1 '06 #1
6 27671
Connecting to the database...
Connected.
Making 2nd connection to exported datasource: SiebSrvr_IBMLABES...
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_FLD ... 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.
Oct 1 '06 #2
Niheel
2,460 Expert Mod 2GB
Merged your threads. Please keep related posts in one thread instead of posting multiple threads.
Oct 1 '06 #3
r035198x
13,262 8TB
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?
Oct 2 '06 #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?


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
Oct 2 '06 #5
r035198x
13,262 8TB
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.
Oct 2 '06 #6
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 ...
Sep 27 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Peter Bassett | last post by:
I haven't programmed in Java for awhile and forgot how to get this to work. I have a program ListFiles developed in c:\java which lists every .JPG and ..GIF file in a folder. It works fine...
3
by: Sean Cleary | last post by:
In Java How to program, 5th edition, I can not get past the example in chapter 3, page 89 to page 96. Is there some errata for this? I did not/could not load all the tools. I am coming from Slick...
1
by: sylsau | last post by:
Hello, I wrote a JAVA program which uses the JAVA API JDOM 1.0 (of this site www.jdom.org) I put the archive jdom.jar in the directory /usr/share/java/jdom.jar and I added this path in the...
4
by: AshishMishra16 | last post by:
HI friends, I am using the Flex to upload files to server. I m getting all the details about the file, but I m not able to upload it to Server. Here is the code i m using for both flex & for...
4
nexcompac
by: nexcompac | last post by:
Ok, I posted a similar post but now need to jump back into it. Here is what I have been able to clean up. I am using textpad and jbuilder. Still getting used to the whole java world and I am...
11
by: hamiltongreg | last post by:
I am new to Java and am having problems getting my program to compile correctly. My assignment is as follows; Choose a product that lends itself to an inventory (for example, products at your...
1
Nepomuk
by: Nepomuk | last post by:
Hi! I'm trying to run an external Program with Process p = Runtime.getRuntime().exec("/bin/sh -c \"/bin/gzip -c /home/user/workspace/TarGz/pics.tar > pics.tar.gz\""); CleanStream cleanError =...
4
lifeisgreat20009
by: lifeisgreat20009 | last post by:
This is what i am getting on running the program......... C:\PROGRA~1\Java\JDK15~1.0\bin>javac Editor.java Note: Editor.java uses or overrides a deprecated API. Note: Recompile with...
16
by: Knute Johnson | last post by:
I'm trying to write a C wrapper to run a Java program. I need to distribute a CD with the Java runtime, my application and a C startup program. I've put the C wrapper program, my java app and the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.