Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within I/O and Streams
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Tim Cooke
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Liutauras Vilda
Sheriffs:
Rob Spoor
Junilu Lacar
paul wheaton
Saloon Keepers:
Stephan van Hulst
Tim Moores
Tim Holloway
Carey Brown
Scott Selikoff
Bartenders:
Piet Souris
Jj Roberts
fred rosenberger
Forum:
I/O and Streams
Problem while Reading File
Bibhudutta Pradhan
Ranch Hand
Posts: 31
I like...
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
The program gives the out put but with the missing first letter of every line.
Please Help
try { FileReader fileReader = new FileReader("D:\\Amit\\bibhu\\a.txt"); BufferedReader bfr = new BufferedReader(fileReader); while(bfr.read()!=-1) { String s = bfr.readLine(); System.out.println(s); } } catch(Exception e) { e.printStackTrace(); }
Koen Aerts
Ranch Hand
Posts: 344
I like...
posted 10 years ago
2
Number of slices to send:
Optional 'thank-you' note:
Send
Your bfr.read() call reads a single character each time, after which your readLine() gets the rest of the line. Use this instead:
String s; while ((s = bfr.readLine()) != null) { ... }
Rajasekhar Pentakota
Ranch Hand
Posts: 39
I like...
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
The pointer moves forward. when you use read() method it moves the pointer one character right.
Thanks
Raja
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Reading a file and storing its contents into a String Array
EOF
What's wrong with the program?
Read file X lines
To find a largest sector in a given input string of 1's and 0's
More...