Forums Register Login

Reading file using FileChannel

+Pie Number of slices to send: Send

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
+Pie Number of slices to send: Send
CarefullyChooseOneForum while posting. Moving to IO and Streams forum ..
+Pie Number of slices to send: Send
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.
Whatever. Here's a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 6307 times.
Similar Threads
How do I read and write a binary file?
Reading text files
how to read a file data into byte array
How to replace a line in a file
New IO
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 14:02:32.