Results 1 to 7 of 7
  1. #1
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    127
    Rep Power
    0

    Default BufferedReader always skipping the first line.

    So im building a little notepad application that saves and reads a txt file from your computer.

    But everytime i open the application again it loads the lines, but not the first line. that one always disappears.

    Don't ask me what i tried, i tried everything i KNOW.


    code for the bufferedreader:

    Java Code:
    final JTextArea textArea = new JTextArea();
    		textArea.setBounds(139, 136, 371, 130);
    		getContentPane().add(textArea);
    		try{
    			FileReader fr = new FileReader("C:\\Users\\Home\\Desktop\\Send.txt");
    			BufferedReader br = new BufferedReader(fr);
    			String text = br.readLine();
    			while((text = br.readLine())!=null){
    				textArea.append(text+"\n");
    			}
    			br.close();
    			}catch(IOException e){
    				System.out.println(e);
    			};
    Never give up.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default Re: BufferedReader always skipping the first line.

    What does the code do with the data that is read on line 7?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,279
    Rep Power
    6

    Default Re: BufferedReader always skipping the first line.

    Quote Originally Posted by Norm View Post
    What does the code do with the data that is read on line 7?
    To make it more oblivious:

    What does the code do with the line that is read on line 7?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    127
    Rep Power
    0

    Default Re: BufferedReader always skipping the first line.

    Quote Originally Posted by Norm View Post
    What does the code do with the data that is read on line 7?
    What are you talking about lmao

    It reads every line except the first one
    Never give up.

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,923
    Rep Power
    5

    Default Re: BufferedReader always skipping the first line.

    Quote Originally Posted by MR bruto View Post
    It reads every line except the first one
    Nope! You are squashing the first line.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default Re: BufferedReader always skipping the first line.

    It reads every line except the first one
    What line does it read here:
    Java Code:
     String text = br.readLine();
    What does it do with the line after it reads it?
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    127
    Rep Power
    0

    Default Re: BufferedReader always skipping the first line.

    Quote Originally Posted by Norm View Post
    What line does it read here:
    Java Code:
     String text = br.readLine();
    What does it do with the line after it reads it?
    Holy shit i see.
    Thanks brothers
    Never give up.

Similar Threads

  1. Scanner skipping every other line
    By Dex in forum New To Java
    Replies: 2
    Last Post: 08-14-2012, 10:32 AM
  2. BufferedReader.readLine() slow reading long line.
    By sumarlidason in forum Networking
    Replies: 9
    Last Post: 06-21-2012, 09:06 PM
  3. The Simple, Infamous Line-Skipping ".nextLine()" Method
    By CuppaCoffee in forum New To Java
    Replies: 4
    Last Post: 01-30-2012, 06:04 AM
  4. Skipping an Integer
    By BrainMelt in forum New To Java
    Replies: 9
    Last Post: 03-30-2011, 05:54 AM
  5. skipping input
    By windie_86 in forum New To Java
    Replies: 1
    Last Post: 02-12-2008, 08:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •