473,655 Members | 3,112 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

program to find a perticular string in a file using java

5 New Member
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
Oct 1 '06 #1
6 27688
gauravkhanna
5 New Member
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.
Oct 1 '06 #2
Niheel
2,456 Recognized Expert Moderator Top Contributor
Merged your threads. Please keep related posts in one thread instead of posting multiple threads.
Oct 1 '06 #3
r035198x
13,262 MVP
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
gauravkhanna
5 New Member
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 MVP
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
seenathinks
1 New Member
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
3973
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 running from that folder. It takes 1 argument, the pathname, so a command could be "java ListFiles ." But if I try to run it from another folder, using "java c:\java\ListFiles ."
3
2406
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 edit and from Dos, and they both say that my copying of that example is flawed. Now I made a change: the name of the file is Lab2.java, the html file is Lab2.html. The contents of my Java file is:
1
2215
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 CLASSPATH variable. The program runs normally when I launch it in a unix shell. Now, I want to launch this JAVA program in a PHP program with system() function for example. I have an Apache server with PHP 4 who runs. The
4
6212
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 Struts: import java.io.File; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Enumeration; import java.util.Iterator;
4
2306
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 trying to compile a program using TextPad. Here is what I have so far. /* * Main.java * * Created on July 19, 2007, 5:54 PM *
11
7690
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 workplace, office supplies, music CDs, DVD movies, or software). • Create a product class that holds the item number, the name of the product, the number of units in stock, and the price of each unit. • Create a Java application that displays the...
1
7571
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 = new CleanStream(p.getErrorStream(), "ERROR"); CleanStream cleanOutput = new CleanStream(p.getInputStream(), "OUTPUT"); clearError.start(); clearOutput.start(); p.waitFor(); under Linux.
4
2123
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 -Xlint:deprecation for details. I did run the program like this after compiling it using javac command......... I get this........
16
3403
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 runtime directories in the same directory. It will run under MS XP or maybe Vista. I'm using MS Visual C++ Express 2005 for a compiler and I tried using the _execl and _spawnl functions. These all give me assertion errors and file not found...
0
8296
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8710
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8497
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8598
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7310
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5627
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4299
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2721
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1598
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.