Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2011
    Rep Power

    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);
            catch(FileNotFoundException e) {
                System.out.println("Kan bestand niet vinden");
            catch(IOException e) {
                System.out.println("Fout bij het lezen of sluiten bestand");
            this.tekst = stringbuilder.toString();
            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
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    Default Re: reading a text file

    Remove line #5.

    kind regards,

    I have the stamina of a seal; I lie on the beach instead of running on it.

Similar Threads

  1. Reading text from .txt file
    By Colossus in forum New To Java
    Replies: 5
    Last Post: 01-24-2012, 06: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-08-2010, 12:47 AM
  4. reading text file
    By trofyscarz in forum New To Java
    Replies: 1
    Last Post: 02-05-2010, 03:24 AM
  5. Reading text file
    By Lennon-Guru in forum New To Java
    Replies: 1
    Last Post: 12-16-2007, 12:38 AM

Posting Permissions

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