Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: how to call a string inside a while loop

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Location
    philippines
    Posts
    28
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Post how to call a string inside a while loop

    How to call a string inside the "while loop"?
    like this:
    while((line = br.readLine())!=null){
    String acc[] = line.split("-");
    String account = acc[0];
    String passcode = acc[4];
    }

    i would like to declare a string outside the "while loop" or "try catch" as the same as of the inner String.

    try{
    File file = new File("Database.txt");
     
    BufferedReader br = 
     
    new BufferedReader(new FileReader(file));
     
    String line;
     
    while((line = br.readLine())!=null){
     
     
    String acc[] = line.split("-");
     
    String account = acc[0];
     
    String passcode = acc[4];
     
    }
     
    br.close();
     
    }
     
    catch (IOException ex) {
     
    ex.printStackTrace();
     
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: how to call a string inside a while loop

    declare a string outside the "while loop"
    The String line is declared outside of the while loop. Use that as an example of how to declare variables outside of the loop.

    Please edit the code and add indentations for nested statements to make the code easier to read.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. New to Java, need help with arrays inside a loop please!
    By Darkaudicate in forum Loops & Control Statements
    Replies: 1
    Last Post: November 21st, 2012, 06:32 PM
  2. New to Java, need help with arrays inside a loop please!
    By Darkaudicate in forum Java Theory & Questions
    Replies: 3
    Last Post: November 21st, 2012, 02:48 PM
  3. [SOLVED] Nimbus PLAF: and a double call to repaint() inside a runnable interface
    By chronoz13 in forum AWT / Java Swing
    Replies: 15
    Last Post: August 11th, 2012, 12:59 AM
  4. Timer inside loop
    By dove in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 26th, 2012, 09:57 AM