Void and return help

whats the difference of using void and using the return?
i used last time the void and return, but the outputs of the two are the same

CodeSniffer wrote:
raychen wrote:
Using return within a method that returns void is just a quick way to go all the way to the end of the method. It is a goto in disguise, but sometimes it may make your code cleaner.yeah, thats what i saw when im trying to figure out whats the diff of the twoAsking about the difference between void and return is like asking about the difference between being bald and leaving your house. The two are not in any way related, and there's no context in which you can choose between one and the other.
You're going to have to clarify your question.
Do you know what void means?
Do you know what return does?
If you answered yes to both, then I really have no idea what you're confused about.

Similar Messages

  • Void and return statments.

    Hi, I have this a problem ( for reference 4.28 in the blue jay book) where i need the method public Lot removeLot(int number)
    The program works fine and it does everything it's supposed to do but..
    The problem is that I had to change lot to void in the method's signature. By the way, im using the java.util and java.arraylist packages.
    Any help is appreciated.
    Edit
    This may help
    public void removeLot(int number)
    if(number < 0) {
    System.out.println("This is not a valid number, please enter a new number");
    else if (number < lots.size())
    lots.remove(number);
    I want Lot instead of void.
    Edited by: tiowa on Nov 17, 2008 4:37 AM

    tiowa wrote:
    I am supposed to return the lot number that was entered.The lot number? Are you sure? Because the lot number is already the input parameter. Why would you want to return that?
    I think it's more likely that you should return the Lot object that was removed.
    And when I try to compile it gives the error that there is no return statement in the method.When you post about an error always post the complete error message.
    I find out it was because the return statement was in the if statements.Partially. The problem was that you did not return a value in every case.
    When I make a return statement outside of the ifs, then it compiles.That's one possible solution but obviously not the desired one (as you return the same value in each case, which kind of defeats the use of a return value).

  • Sychronized Thread  and return Help

    Hi I am fairly new to Java and I am a bit confused on how to carry out this Operation and I could do with a fee suggestions
    I ve got a aa class Decoder that implements runnable and when called it outputs and array.
    Where my problem is that I am not quite sure on how to return that array.I ve declared the ouput as public but I am a lil confused on where to stick get output to get back my results
    Thanks for your help in advance
    cheers
    chib
    class decoder implements runnable{
    run()
    do something
    synchronized setinput()
    synchronised getoutput()
    }

    Is it really a Thread you want to create? If you depend on the output of the calculation you should usually use a conventional method so that the caller will wait for the calculation to finish and use its results. If it really is a concurrent task, the result of which you need at some later time, use a class implementing Runnable, which holds the result with one of its fields:
    public Decoder  implements Runnable {
      private InputType   in;
      private ReturnType  ret;
      private volatile boolean  done;
      public Decoder(InputType in) {
        this.in   = in;
        this.done = false;
      // not blocking test if done
      public boolean isDone()  { return  done; }
      // blocking request for return value
      public synchronized ReturnType getResult() {
        while(!done) try {
          wait();
        catch(InterruptedException e)  {}
        return  ret;
      public synchronized void run() {
        ret  = doCalc(in);  // some complex calculation
        done = true;
        notifyAll();

  • Need help in Exporting list to memory and return in background

    Hello Experts,
    I have a program which reads data from mc.9 by exporting list to memory.When I run it in foreground its working fine . However if I schedule it as a  background program it is unable to get list from memory.
    Any help will be appreciable.
    Thank you

    Hi jayaram,
    I tried to do as you said. Its creating spool request and status to completed (sm37 instead of sm36 bcoz i don't hv authorization in production server). Now I didn't see any errors in job log. But data coming to ztable is as usual ( all are ZEROS).
    Hey when i tried doing it as below
      SUBMIT RMCB0300 WITH SL_WERKS-LOW = P_WERKS
                      WITH SL_LGORT = 'W001'
                      WITH SL_SPMON-LOW = P_FPERIOD
                      WITH SLV_NO = 'MC.9N'
                      WITH SL_SPMON-HIGH = P_FPERIOD EXPORTING LIST TO MEMORY AND RETURN .
      CALL FUNCTION 'LIST_FROM_MEMORY'
        TABLES
          LISTOBJECT = LISTOBJECT
        EXCEPTIONS
          NOT_FOUND  = 4
          OTHERS     = 8.
      IF SY-SUBRC <> 0.
        if SY-SUBRC = 4.
          message 'not_found' type 'i'.
        ELSEIF SY-SUBRC = 8.
          message 'others' type 'a'.
        endif.
      ENDIF.
    I found that my job with completed status but with in job log i found error of type I means that the error is with notfound type in exceptions.
    Hey sorry for the postings may be due to some issues Im unable to see what i have replied in postings that's why im posting repeatedly..
    Edited by: Praveen Pathuri on Apr 23, 2009 7:30 AM
    Edited by: Praveen Pathuri on Apr 23, 2009 7:55 AM

  • Help! 2 iPhones and 1 laptop.my partner synced his phone first-everything was fine. Then he done the same to my phone and it deleted EVERYTHING and returned to factory settings

    My partner has deleted everything from my phone and returned it to factory settings accidenly. Our old computer crashed and we have been trying to get all the stuff from our phones onto the new laptop. He managed to sync his phone but then he done mine and it deleted it all. Someone help please x

    On iTunes on the computer, go to:
    Edit, Preferences, Devices and see if there is a backup listed for your iphone.
    If so, restore it from that backup.

  • Find an iphone 5 in the club and i want you to help me find the owner and return it to the user.  its been erased and no sim card in it .when i try to configure , it says i should enter an apple  and a password.

    find an iphone 5 in the club and i want you to help me find the owner and return it to the user.
    its been erased and no sim card in it .when i try to configure , it says i should enter an apple
    and a password.

    Since it was erased and no sim card the owner probably got rid of it of some reason.

  • I have an iPhone 5 and recently when I try to copy and paste the app freezes and returns to the home screen please help.

    When I try to copy paste my app freezes and returns to the home screen please help.

    Try resetting ...
    Press and hold the Sleep/Wake button and the Home button together for at least ten seconds, until the Apple logo appears.
    If that didn't help, tap Settings > General > Reset > Reset All Settings
    Then restart your iPhone.

  • HELP: I need to link a PDF within PDF and be able to open and return to original PDF

    I have a master PDF and have attached 7 supplemental PDF documents. I created "click here" icons and used the steps below so that the linked document would open. The problem is, once I open the supplemental PDF, it closes the original master. I would like to close the linked document and return to the master view. Is there a way to do this?
    Or is there a way to do this from InDesign? I created master file in InDesign and exported as an Interactive PDF.  I created the buttons and linked them to external files. This works great as long as the master PDF and the links are all in one file, but that is a pain to send to a viewer. Ideally, I want to be able to send the master PDF to a viewer and not have to send a links folder. Is there a way to embed the supplemental PDFs into the master so that they are all combined into one file AND have the ability to use buttons to call up one of the attachments, close, and return to the original?
    Thanks in advance!!

    I want to do the same thing that the original poster of this question wants to do. I haven't worked extensively with Acrobat so am finding by trial and error the several ways PDFs within PDFs can be accomplished. I'm using a trial version of Acrobat Pro X and have experimented with three options.
    1 - I've created a Portfolio and am impressed with what that can do, though I think it may be "overkill" for the current size of my project.
    2 - I've also tried creating this project as an index but discovered that the links I'd created in the original docs didn't work when I moved the index and its contents (keeping the file structure the same). I presume this means the links are absolute? I also don't understand how it is that users search a .pdx file, or how to present what I want to be the original opening PDF of indexed docs.
    3 - I've also thought to create one PDF with attached PDFs, so I'd like to have you expand on your comment about creating a master document and attaching documents to it.
    The specifics of my project are these: I have created a master directory that contains approximately 120 links. Most of the links are repeated three times (users can find in the directory the item they need in three different ways: alphabetically, by application, or by module; hence each item listed once in each of three categories). I want to make that directory the "master" PDF that users open first, and then locate within that PDF the 5-8 PDF documents that contain all of the places to which the directory links. I want the "master" directory to be self-contained and completely "portable" as far as all of the documents and links are concerned so that when I make the PDF available from our website users can open the master from there or copy it and have all of the docs they need with all of the links intact. I think I prefer that all docs open in new windows, since returning to the original doesn't seem very user friendly in Acrobat (I like the tabs feature in FoxIt when multiple PDFs are open...).
    I'd like an opinion about the best way to accomplish what I need to do, and am also wondering whether there are other options I am unaware of. BTW, the reason we've decided to document this whole project in PDFs rather than HTML is because this project contains a big number of tables, which do not look consistent across various browsers (i.e., most of our tables look fine in IE and Firefox, but awful in Google Chrome...). In researching my issue on the Acrobat Windows forum I see that rendering tables in Acrobat is also an issue that seems to be unresolved.
    Thank you!

  • Difference between void and null?

    wht is da difference between void and null w.r.t java?

    corlettk wrote:
    Why do you care, unless you're implementing a java compiler or JVM?Wow, you sure do suck at helping out in a forum. Why even make this post? You're not helping the OP any, and you made yourself look like a tool.
    To the op:
    Null is java's version of a null value. Java's version is more strict then many other languages, and will not work in a boolean expression or anywhere code expects a real and not null value. It's simply null.
    Void is java's way of declaring no return type on a method. Methods that are void take no 'return' statement and if one is provided will cause a fatal error. The exception to this is using 'return' without a value, which returns control to the caller of the method.
    Observe:
    //this method returns an int
    public int return_int(){
        int value = 5;
        return value;
    //this method does not return an int
    public void return_nothing(){
        int another_value = 123;
        System.out.println("Here's the value: " + return_int());
    //this method does not return anything
    public void nothing_returned(){
        return_nothing();
        return;
        System.out.println("This line never gets printed; the method returned control already!");
    }

  • Void and Reissue Payments

    We have a scenario where a factor(associated with more than a hundred suppliers) has a payment returned from bank.
    For the above scenario there could potentially be hundreds of checks involved if a factor's payment is returned as payables processs a seperate ACH for each supplier attached to the factor.
    How can we customize or use the void and reissue program to enter a vendor number, factor number,factor site number or batch name, number(some sort of identifier) so as to prevent void and reissue each check.
    This is of high priority, any help, suggestions are greatly appreciated.
    Thanks in advance

    Hi Vetri
    following is how xml looks like:
    <PositivePayDataExtract>
    <OutboundPayment>
    - <PaymentStatus>
    <Code>VOID</Code>
    <Meaning>VOID</Meaning>
    </PaymentStatus>
    - <PaymentAmount>
    <Value>100</Value>
    </OutboundPayment>
    <OutboundPayment>
    - <PaymentStatus>
    <Code>ISSUED</Code>
    <Meaning>Printed</Meaning>
    </PaymentStatus>
    - <PaymentAmount>
    <Value>200.19</Value>
    </OutboundPayment>
    </PositivePayDataExtract>
    When the detail records are @ level of <Outboundpayment> group. Here this will go for 2 times like for
    example
    accountno123 check no0001 100 ABC Corp
    accountno234 check no0002 200 ABC Corp
    Now when I write SUM @level of <PositivePayDataExtract> group..So it goes for only ONCE.
    totaldetail_record_count=2 total_amount_300 ....[should be 200-100=100]
    When I write your syntax like @<PositivePayDataExtract> group it just check ONLY ONCE and at the first record it cheks for condition
    SUM((OutboundPayment/PaymentAmount[OutboundPayment/PaymentStatus/Code ='ISSUED']/Value))
    SUM(OutboundPayment/PaymentAmount/Value
    [OutboundPayment/PaymentStatus/Code=’VOID’])
    BUT it DOES NOT go to 2nd record.
    Bank wants SUM in one line..and still struggling..
    Any thoughts?
    thanks
    kp

  • Whats the difference between producing output and returning a value?

    I've just started learning Java. I am having difficulty understanding what it means to "return a value".
    If a method has an argument, then whenever this method is called the variable named will be used for output.
    If you create a method to return a new value rather than display it, you would exchange the 'void' for 'double' e.g. public static double predictRaise(double moneyAmount). My book states that a return statement causes a value to be sent from a called method back to the calling method. Their example is not clear to me. Here is what they show for when only 'output' is produced:
    <code>
    Public static void predictRaiseUsingRate (double money, double rate)// 2 arguments
              double newAmount;
              newAmount = money * (1 + rate);
              System.out.println (?With raise, new salary is ? + newAmount);
    </code>
    And their example of a returned value:
    <code>
    public static double predictRaise(double moneyAmount)
              double newAmount;     
              newAmount = moneyAmount * 1.10;
              return newAmount;
    </code>
    Their explanation: "This return statement causes a value to be sent from a called method back to the calling method. The value stored in newAmount is      sent back to any method that calls predictRaise() method."
    For some reason this is just not sinking in. Does anyone have a better example/explanation? I could not find anything with a better explanation in archives.
    Are they tring to tell me: "if the original method declares an argument that is declared as 257 in the method call, that when that same method is called again, it will always be 257? But if you do a return statement, any changes in the return statement will now always be used in all methods calling that method?
    Thanks for your help.
    Gizelle

    To use an older and possibly more easily understood terminology. Methods can either be "functions" almost in the mathematical sense or they can be "procedures" in the sense of a process.
    A function is a mapping between a "domain", its arguments, and a "range", its result. An example of a function in mathematics is cosine, which takes an argument in degrees or radians and returns a result between -1 and 1. In java functions are just methods that declare a result type. eg. public int foo(int arg).
    A procedure is a program that doesn't return any result, it's not something that fits well into mathematics, but it occurs all the time in real life. For example, walking the dog does not map something from a domain to a range, but it may have some side effects, which is why I always carry a plastic bag with me. Procedures in java are methods that are declared as "void". eg. public void foo(int arg).
    All the well known arithmetic operations are functions, they take one or two arguments in the domain of numbers and return a result in the same set. Eg, x = a + b, the operator + is a function that takes two numbers, calculates the arithmetic sum of them and returns a result. Functions are very handy since you can string them together, eg. z = a+foo(b)*max(c+d). This doesn't work with procedures.
    Procedures are often used for much longer and more involved operations, there is no immediate result, but a lot of things may occur while they run. Data may be printed on a screen or paper, a database or file may get updated and email messages might get send. But no other expession is waiting for a resulting value so it can carry on. Procedures may also happen asynchonously, ie. outside the timeframe of their caller, see threads. Functions cannot do this, or if they do, they turn into procedures by throwing away their result. For example, you can schedule a procedure to send an email to your friends every Friday inviting them to go out for drinks, but you don't wait around for the result.
    In a way functions are a bit like phone calls, you wait for a response, procedures are more like snail mail, you send it off and check on what happened later.
    I hope this helps.

  • Creating a function and return something from an XML file

    Hi!
    I'm working with timeline actionscript. I want to create a function that loads my xmlfile and returns an xmlobject with the file's content.
    This is what I got so far:
    my_btn.addEventListener(MouseEvent.CLICK, getXML("myxml.xml")); //1067: Implicit coercion of a value of type void to an unrelated type Function.
    function getXML(fn:String):void{
         var infoLoader:URLLoader = new URLLoader();
         infoLoader.addEventListener(Event.COMPLETE, xmlLoaded);
         infoLoader.load(new URLRequest(fn));
         var myXML:XML = xmlLoaded(); //1136: Incorrect number of arguments.  Expected 1.
         trace(myXML);
    function xmlLoaded(e:Event):XML{
         return e.target.data;
         //trace(e.target.data);
    Can anyone take a look and perhaps point me in the right direction?
    Thanks

    I have never used a listcomponent, so I can only help with the steps before filling it with data.
    I think you should at start of your application load the XML with filenames and just after it's completed, e.g. in Event.COMPLETE handler, load all other XMLs looping through filenamesXML, like this
    var filenamesXML:XML;
    var XMLsToLoad:uint = 0;
    function filenamesXMLLoaded(e:Event):void
         filenamesXML = XML(e.target.data);
         XMLsToLoad =  filenamesXML.filenames.children().length();
         for (var i:uint =1; i < filenamesXML.filenames.children().length(); i++)
                  getXML( filenamesXML.filenames.children()[i] ); // the function from my previous post, don't forget to implement it
    //modify the minor xml load handler from the previous post
    function xmlLoaded(e:Event):void
         var loadedXML:XML = XML(e.target.data);   
         xmlArray.push(loadedXML);
         XMLsToLoad--;
    //assign the one click handler to all buttons, a loop here would be quite handy
    function clickHandler(e:MouseEvent):void
         if (XMLsToLoad == 0) //check if all xmls have been completely loaded
              switch (e.target.name) // swith by clicked button's instance name
                   case "button_1":
                        // here you have to implement supplying listcomponent with data, I think a loop again will be a good idea
                        break;
                   case "button_2":
                        // ibid.
                        break;
    Regards,
    gc

  • CLR Procedure and returning large number of rows

    I have a CLR stored procedure coded in C# that retrieves data from a web service, and returns that data using SendResultsStart/SendResultsRow/SendResultsEnd. This all works fine, except when the data from the web service is tens or even thousands of records.
    The code itself takes about 3 minutes on average to do all it's work with around 50000-60000 records, but the procedure does not return in SSMS for about another 10-15 minutes, during which time the CPU and memory usage go up significantly.
    To rule out any of the CLR code as the culprit, I created a very simple CLR procedure that just loops to return 100000 records with int and nvarchar(256) fields with the current count, and "ABC" followed by the count.  Here is the code:
    [Microsoft.SqlServer.Server.SqlProcedure]
    public static void ABC()
    System.Diagnostics.Stopwatch ExecuteTimer = System.Diagnostics.Stopwatch.StartNew();
    SqlMetaData[] ResultMetaData = new SqlMetaData[2];
    ResultMetaData[0] = new SqlMetaData("count", SqlDbType.Int);
    ResultMetaData[1] = new SqlMetaData("text", SqlDbType.NVarChar, 256);
    SqlContext.Pipe.SendResultsStart(new SqlDataRecord(ResultMetaData));
    for (int x = 0; x < 100000; x++)
    SqlDataRecord ResultItem = new SqlDataRecord(ResultMetaData);
    ResultItem.SetValue(0, x);
    ResultItem.SetValue(1, "ABC" + x.ToString());
    SqlContext.Pipe.SendResultsRow(ResultItem);
    SqlContext.Pipe.SendResultsEnd();
    TimeSpan ExecTime = ExecuteTimer.Elapsed;
    SqlContext.Pipe.Send("Elapsed Time: " + ExecTime.Minutes.ToString() + ":" + ExecTime.Seconds.ToString() + "." + ExecTime.Milliseconds.ToString());
    I then executed procedure ABC in SSMS, and it took 21 minutes to return.  All of the data rows were visible after just a couple of seconds, but the query continued to run as the CPU and memory went up again.
    Is this really how long it should take to return 100000 rows, or am I missing something?  Is there a better approach than using SendResultsStart/SendResultsRow/SendResultsEnd?
    I've googled this to death and haven't found anything that helped or even explained why this is.
    I would greatly appreciate any suggestions or alternate methods to achieve this faster.
    Thanks!
    Alex

    When you create a new object, space on the garbage-collected heap is allocated for that object, and the address will be stored in a reference. Some time later, there will no longer be any references that hold the address of the allocated object. It doesn't
    matter whether the reference count went to 0 because the reference was set to null or because the reference was on the stack and is no longer in lexical scope, the end result is the same: the garbage collector will, at some point in time, have to perform the
    book-keeping operations necessary to identify that the space allocated for that now-unreferenced object can be re-used. When, on the other hand, you only create a single SqlDataRecord object and hold onto the reference, all of the book-keeping operations
    associated with creating 100,000 objects are eliminated. This is why the documentation for the SqlDataReader class advises that:
    When writing common language runtime (CLR) applications, you should re-use existing
    SqlDataRecord objects instead of creating new ones every time. Creating many new
    SqlDataRecord objects could severely deplete memory and adversely affect performance.

  • JSP and Servlet - help please

    Hello,
    I am making this feedback for fun and a bit of learning too. I have an INDEX.JSP page, where the user selects the very first option. Depending upon the selected option he is moved another page PRODUCTFEEDBACK.JSP (so far I have completed this). Here as usual there are many fields to be filled in. As a spams protection i have done this;
    I have a AdditionClass, which is a seperate class where two number are generated at random. This numbers are called by PRODUCTFEEDBACK.JSP. The user is then asked to perform the addition. The completed form is then sent to ProductFeedback servlet.
    When I compile my PRODUCTFEEDBACK.JSP I get this error. Can you please tell whats wrong?
    PRODUCTFEEDBACK.JSP
          *<td>Please help us to prevent Spams by performing this simple mathematical Calculation. We appreciate your effort </td>*
        *</tr>*
      *</table>*
      *<jsp:useBean id = "AddTest" class = "go.AdditionClass" />*
      *<table width="53%"  border="0" align="center">*
        *<tr>*
          *<td><div align="center">*
      *<input name="textfield8" type="text" size="3" value ="<jsp:getProperty name="AddTest" property = "randNum1" />">*
    *  + * 
      *<input name="textfield9" type="text" size="3" value="<jsp:getProperty name="AddTest" property = "randNum2" />">*
    *  = *
    *<input name="_total" type="text" size="5">*
          </div></td>
        </tr>
        <tr>
          <td> </td>
        </tr>
      </table>
      <br>
      <table width="37%" height="23"  border="0" align="center">
        <tr>
          <td width="33%"> </td>
          <td width="67%"><input type="submit" name="Submit" value="Click here to send us this form"></td>
    AdditionalClass.java
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package go;
    import java.util.Random;
    * @author MAC
    public class AdditionClass {
        Random generator = new Random();
        int randNum1; // First Random Number
        int randNum2; // Second Random Number
        public void SetNum1(){
            randNum1 = generator.nextInt(10); // Generate First Random Number
        public int getNum1(){
            return randNum1; //Return First Random Number
        public void SetNum2(){
            randNum2 = generator.nextInt(10); // Generate Second Random Number
        public int getNum2(){
            return randNum2; // Return Second Random Number
        // send the Random Numbers to ProductFeedback class
        public void productFeedbackRandNum1(){
            ProductFeedback productfeedback = new ProductFeedback();
            productfeedback.randomNumber1(randNum1);
        public void productFeedbackRandomNum2(){
            ProductFeedback productfeedback = new ProductFeedback();
            productfeedback.randomNumber2(randNum1);
    }Erros that I am getting:
    org.apache.jasper.JasperException: Cannot find any information on property 'randNum1' in a bean of type 'go.AdditionClass'
    C:\Documents and Settings\MAC\My Documents\NetBeansProjects\FeedBack\nbproject\build-impl.xml:462: The following error occurred while executing this line:
    C:\Documents and Settings\MAC\My Documents\NetBeansProjects\FeedBack\nbproject\build-impl.xml:440: Java returned: 1
    BUILD FAILED (total time: 1 second)

    Thank you for replying. I modified my Bean class then what is posted above, so thought to repost the code again and seek help. There seems to be no error now but it just dont generate any random numbers, All i get very time is 0. I am wondering, is my code generating 0 as random number, every time :-)
    package go;
    import java.util.Random;
    public class AdditionBean {
        int randNum1; // First Random Number
        int randNum2; // Second Random Number
        public void generateRandomNum1(){
            Random generator = new Random();
            int num1 = generator.nextInt(10);
            SetRandNum1(num1);
            // Send num1 value to ProductFeedback.java
            ProductFeedback productfeedback = new ProductFeedback();
            productfeedback.randomNumber1(num1);
        } // End of generaeRandomNum1
        public void generateRandomNum2(){
            Random generator = new Random();
            generator = new Random();
            int num2 = generator.nextInt(10);
            SetRandNum2(num2);
            // Send num1 value to ProductFeedback.java
            ProductFeedback productfeedback = new ProductFeedback();
            productfeedback.randomNumber2(num2);
        } // End of generateRandomNum2
        public void SetRandNum1(int num1){
            randNum1 = num1;
        public int getRandNum1(){
            return randNum1; //Return First Random Number
        public void SetRandNum2(int num2){
            randNum2 = num2;
        public int getRandNum2(){
            return randNum2; // Return Second Random Number
    }// End of classThank you,

  • Search for a word and return all the  lines (row) from the text file..

    Hi all,
    I need a help on how to search a string from the text file and returns all the lines (rows) where the searched string are found. I have included the code, it finds the indexof the string but it does not return the entire line. I would appreciate your any help.
    public class SearchWord
         public static void main(String[] args){
         //Search String
         String searchText = "man";
         //File to search (in same directory as .class file)
         String fileName = "C:\\Workspace\\MyFile.txt";
         //StringBuilder allows to create a string by concatinating
         //multiple strings efficiently.
         StringBuilder sb =
         new StringBuilder();
         try {
         //Create the buffered input stream, which reads
         //from a file input stream
         BufferedInputStream bIn =
         new BufferedInputStream(
         new FileInputStream(fileName));
         //Holds the position of the last byte we have read
         int pos = 0;
         //Holds #of available bytes in our stream
         //(which is the file)
         int avl = bIn.available();
         //Read as long as we have something
         while ( avl != 0 ) {
         //Holds the bytes which we read
         byte[] buffer = new byte[avl];
         //Read from the file to the buffer
         // starting from <pos>, <avl> bytes.
         bIn.read(buffer, pos, avl);
         //Update the last read byte position
         pos += avl;
         //Create a new string from byte[] we read
         String strTemp =
         new String(buffer);
         //Append the string to the string builder
         sb.append(strTemp);
         //Get the next available set of bytes
         avl = bIn.available();
         catch(IOException ex) {
         ex.printStackTrace();
         //Get the concatinated string from string builder
         String fileText = sb.toString();
         int indexVal = fileText.indexOf(searchText);
         //Displays the index location in the file for a given text.
         // -1 if not found
         if (indexVal == -1)
              System.out.println("No values found");
         else
              System.out.println("Search for: " + searchText);     }
    }

    Hi, you can use servlet class and use this method to get the whole line of searched string. You can override the HttpServlet to treat that class as servlet.
    public class ReportAction extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    //write your whole logic.
    BufferedReader br = new BufferedReader(new FileReader("your file name"));
    String line = "";
    while(line = br.readLine() != null) {
        if(line.contains("your search string")) {
            System.out.println("The whole line, row is :"+line);
    }

Maybe you are looking for