Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2011
    Location
    Belgium
    Posts
    25
    Rep Power
    0

    Default reading a text file

    I have this method that should return a String. Everything works just fine but the first and last line of my textfile isn't shown. How can I solve this? Just found out that only the pair lines of the text file are stored in the tekst string and not the unpair and pair lines.

    private BufferedReader in;
    private String regel;
    private String bestand;
    private StringBuilder stringbuilder;
    private String tekst;


    Java Code:
        public String leesTekstbestandIn() {
            try {
                in = new BufferedReader(new FileReader(this.bestand));
                while((this.regel = in.readLine())!= null){
                this.regel = in.readLine();
                System.out.println("regel: " + this.regel);
                stringbuilder.append(this.regel);
                }
                in.close();
            }
            catch(FileNotFoundException e) {
                System.out.println("Kan bestand niet vinden");
            }
            catch(IOException e) {
                System.out.println("Fout bij het lezen of sluiten bestand");
                e.printStackTrace();
            }
            this.tekst = stringbuilder.toString();
            System.out.println(tekst);
            return tekst;
        }
    Last edited by The original stinger; 05-14-2012 at 01:59 PM.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,661
    Blog Entries
    7
    Rep Power
    21

    Default Re: reading a text file

    Remove line #5.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Reading text from .txt file
    By Colossus in forum New To Java
    Replies: 5
    Last Post: 01-24-2012, 05:09 PM
  2. Replies: 8
    Last Post: 07-17-2011, 02:38 PM
  3. Reading in a text file
    By TheRealHoff in forum AWT / Swing
    Replies: 10
    Last Post: 02-07-2010, 11:47 PM
  4. reading text file
    By trofyscarz in forum New To Java
    Replies: 1
    Last Post: 02-05-2010, 02:24 AM
  5. Reading text file
    By Lennon-Guru in forum New To Java
    Replies: 1
    Last Post: 12-15-2007, 11:38 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
  •