• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading file using FileChannel  RSS feed

 
Dhaneshkumar Parthasarathi
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

in 11th line code , its not printing the line string value which is reading from the file.

is there any mistake in the code , please let me know if someone knows .

Regards
Dhanesh
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CarefullyChooseOneForum while posting. Moving to IO and Streams forum ..
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you may need a buffer.flip() between lines 6 and 7. Another issue is that there's no guarantee that you will read the entire file with line 6 - you really need a loop to guarantee you keep reading until you reach the end of the file. The same is true if you were using traditional IO with arrays rather than Buffers. Or you could use a RandomAccessFile, which has a readFully() method, much easier.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!