Results 1 to 4 of 4

Thread: file reading

  1. #1
    Ranu is offline Member
    Join Date
    Jun 2010
    Posts
    13
    Rep Power
    0

    Default file reading

    I have a text file with 16 lines in it separated by blank spaces in each line.for e.g,Hi I am Ranu
    I love Java
    like this upto 16.Now when I read the lines :
    Java Code:
    try
                {
                FileInputStream fis = new FileInputStream("//10.66.16.33/Sudarshan/Sudarshan/CompMechDesign/mech.txt");
            BufferedInputStream bis = new BufferedInputStream(fis);
            DataInputStream dis = new DataInputStream(bis);
           while((strline=dis.readLine())!=null)
            {
           count++;
           }
         System.out.println("C:"+count); dis.close();      }
                catch(Exception exx)
                {
                    
                }
    The output is 18.Why is that?
    Last edited by Eranga; 06-26-2010 at 02:31 AM. Reason: code tags added

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Don't use those classes for reading text files.
    Use BufferedReader with FileReader or the Scanner class instead.

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,415
    Rep Power
    25

    Default

    The output is 18.Why is that
    Try debugging your program by printing out each line with its count.
    Looking at the output you will see why the count is 18. I assume that's what you mean when you say the output is 18 vs the output is C:18

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Replies: 9
    Last Post: 10-20-2009, 10:52 AM
  2. Replies: 3
    Last Post: 05-09-2009, 11:31 PM
  3. Reading from file
    By kiab3000 in forum New To Java
    Replies: 0
    Last Post: 03-14-2009, 06:33 PM
  4. reading csv file help
    By fritz1474 in forum New To Java
    Replies: 5
    Last Post: 09-04-2008, 08:41 PM
  5. Right use of file reading ?
    By jurka in forum New To Java
    Replies: 3
    Last Post: 08-27-2008, 08:16 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
  •