Results 1 to 4 of 4
Thread: file reading
- 06-25-2010, 06:33 AM #1
Member
- Join Date
- Jun 2010
- Posts
- 13
- Rep Power
- 0
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 :
The output is 18.Why is that?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) { }Last edited by Eranga; 06-26-2010 at 02:31 AM. Reason: code tags added
- 06-25-2010, 07:52 AM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Don't use those classes for reading text files.
Use BufferedReader with FileReader or the Scanner class instead.
- 06-25-2010, 01:02 PM #3
Try debugging your program by printing out each line with its count.The output is 18.Why is that
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
- 06-26-2010, 02:34 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Yeah print the each line with the counter number you've used. And also for the best practice in catch clause print the stack trace as well.
Similar Threads
-
Reading and Writing the contents of a file to another file
By priyankatxs in forum New To JavaReplies: 9Last Post: 10-20-2009, 10:52 AM -
[SOLVED] how to reading binary file and writing txt file
By tOpach in forum New To JavaReplies: 3Last Post: 05-09-2009, 11:31 PM -
Reading from file
By kiab3000 in forum New To JavaReplies: 0Last Post: 03-14-2009, 06:33 PM -
reading csv file help
By fritz1474 in forum New To JavaReplies: 5Last Post: 09-04-2008, 08:41 PM -
Right use of file reading ?
By jurka in forum New To JavaReplies: 3Last Post: 08-27-2008, 08:16 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks