Results 1 to 6 of 6

Thread: Method does not receive parameter

  1. #1
    Join Date
    Mar 2010
    Posts
    191

    Method does not receive parameter

    Hello,
    I have applied this logic, if i is greater than -1, a method is called and I gave him an argument on File, the BufferedReader and FileReader. Strangely, when I pass the arguments, the method does not give me the desired result, i.e the method does not read lines from txt file in while loop. I do not have any idea of what is going on. If you know how to fix the problem then please help me with this. Thanks in advance.

  2. #2
    Join Date
    Nov 2009
    Posts
    583

    Re: Method does not receive parameter

    Hello,
    I think this is the mistake that you could have made in your code.
    Code:
    while ((line = br.readLine())!=null)
    In other words, when you stop the line returned is null. Then in your second method, you begin to read from the same place, in short, there's nothing to read, so you can spend forever in your second loop. By creating a new BufferedReader (method without argument), then place it at the beginning of lines, I think this should work very well.

  3. #3
    Join Date
    Mar 2010
    Posts
    191

    Re: Method does not receive parameter

    Hello,
    This is my updated code and here it is, if you find any problem in the code then please guide me with the correct
    Code:
    Public class bg
    {
     Public static void hand (String [] args) throws IOException
     {
      File fl = new File("c:\\bidon.txt ");
      FileReader flrd = new FileReader(fl);
      BufferedReader buff = new BufferedReader(en);
      
      String aRechercher = "SET PATH";
      String ln = "";
      int i =-1;
      
      while ((ln = buff.readLine())!=null)
      {
       System.out.System.out.println(row);
       
       if(row.indexOf(aRechercher)!=-1)
       {
        / / System.out.println ( "ligne.indexOf (aRechercher is" + ligne.indexOf (aRechercher));
        System.out.System.out.println("found!");
        i + +;
        System.out.System.out.println("i is" + I);
       }
      }
      
      }
     
     Public static void testmet(File fl, en FileReader, BufferedReader buff)throws IOException
     {
      File fl2 = new File("c:\\bidon2.txt ");
      FileWriter flwri = new FileWriter(fl2);
      BufferedWriter buffwri = new BufferedWriter(flwri);
      String aRechercher = "SET PATH";
      
      String ln = "";
      int i =0;
      while ((ln = buff.readLine())!=null)
      {
       System.out.System.out.println("ln is"+ online);
       i + +;
       if (row.indexOf(aRechercher)!=-1)
       {
        ln + = "bogus";;
        buffwri.write(row);
        buffwri.newLine();
       }
       else
       {
        buffwri.write(row);
        buffwri.newLine();
       }
      }
      System.out.System.out.println("i is" + I);
      buffwri.close();
      
     }
    }

  4. #4
    Join Date
    Dec 2009
    Posts
    192

    Re: Method does not receive parameter

    Hello,
    Even i had a similar kind of a problem in my code. What you say makes sense. I thought the cursor back to the beginning. There's there a way around it anyway to be able to send the file method, the BufferedReader and FileReader? Thanks for the valuable suggestion and also if you have any other alternative that can replace this method then please give let me know, I am interested in it. Thanks in advance.

  5. #5
    Join Date
    Nov 2009
    Posts
    518

    Re: Method does not receive parameter

    Hello,
    You can try something like this
    Code:
    private static void newMethode() throws IOException {
    				File fl = new File("c:\\bidon.txt ");
    FileReader flrd = new FileReader(fl);
    BufferedReader buff = new BufferedReader(en);
     
    		/ / Value to find
    		String aRechercher = "SET PATH";
     
    		/ / Treatment
    		String ln = "";
    StringBuffer strbuff = new StringBuffer();
    		boolean isPresent = false;
     
    		/ / For each row ...
    		while ((ln = buff.readLine()) != null) {
    			/ / Add the ln
    			strbuff.append(row);
    			/ / We check that the text is present in the ln ...
    			if (row.indexOf(aRechercher) != -1) {
    				/ / We found a ln that contains the lookup value, it
    				/ / Add CAN
    				isPresent = true;
    strbuff.append(bogus);
    			}
    			/ / Add the newline
    			strbuff.append('\ n');
    		}
     
    		/ / ... we write a new file if the text was present
    		if (isPresent) {
    			File fl2 = new File("c:\\bidon3.txt ");
    FileWriter flwri = new FileWriter(fl2);
    BufferedWriter bw = new BufferedWriter(flwri);
    bw.write(strbuff.function toString() {
        [native code]
    }());
    bw.close();
    flwri.close();
    		}
    	}

  6. #6
    Join Date
    Mar 2010
    Posts
    191

    Re: Method does not receive parameter

    Hello,
    Thanks for the code, if helped me a lot. I just wanted to go after the explanation, but having reopened the File with no problem.
    I see in your code:
    Code:
    StringBuffer strbuff= new StringBuffer();
    I have never used this buffer, it puts a line in the buffer I presume? Can you please explain me this. Thanks in advance.

Similar Threads

  1. Passing object as a parameter in a method
    By Karumbu in forum Software Development
    Replies: 4
    Last Post: 06-01-2011, 01:07 AM
  2. Method overriding versus method hiding in C#
    By ^MALARVIZHI^ in forum Software Development
    Replies: 4
    Last Post: 25-12-2010, 06:25 AM
  3. Replies: 3
    Last Post: 25-09-2010, 12:26 PM
  4. Replies: 5
    Last Post: 20-03-2010, 05:44 AM
  5. What is method overriding and method overloading in java
    By beelow in forum Software Development
    Replies: 3
    Last Post: 17-11-2009, 08:20 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,002,485.52077 seconds with 16 queries