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:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
I/O and Streams
SeekableByteChannel
meeta gaur
Ranch Hand
Posts: 305
I like...
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
hello.txt
------------------
Hi, ranchers
import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.nio.file.Path; import java.nio.charset.Charset; import java.nio.ByteBuffer; import java.nio.channels.SeekableByteChannel; import java.util.EnumSet; import java.nio.file.StandardOpenOption; class Read{ public static void main(String[] args){ Path path=Paths.get("hello.txt"); try(SeekableByteChannel sbc= Files.newByteChannel(path,EnumSet.of(StandardOpenOption.READ))){ ByteBuffer bf=ByteBuffer.allocate(50); bf.clear(); while(sbc.read(bf)>0){ bf.flip(); System.out.print(Charset.forName("US-ASCII").decode(bf)); //1 System.out.print(Charset.forName("US-ASCII").decode(bf)); //2 break; } } catch(IOException io){ System.err.println(io); } } }
Hi, ranchers
Why doesn't it print two times ?
My one regret in life is that I am not someone else.
- Woody Allen
meeta gaur
Ranch Hand
Posts: 305
I like...
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Got it, i'm sorry this was silly question.
My one regret in life is that I am not someone else.
- Woody Allen
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
ByteBuffer
Parsing huge file without reading into memory
validating a byte array for some encoding
non blocking socket
newBufferWriter
More...