java - Oracle snippet does not give back results -


here have following bit of code taken this oracle java tutorial:

// defaults read try (seekablebytechannel sbc = files.newbytechannel(file)) {     bytebuffer buf = bytebuffer.allocate(10);      // read bytes proper encoding platform.  if     // skip step, might see looks     // chinese characters when expect latin-style characters.     string encoding = system.getproperty("file.encoding");     while (sbc.read(buf) > 0) {         buf.rewind();         system.out.print(charset.forname(encoding).decode(buf));         buf.flip();//line x     } } catch (ioexception x) {     system.out.println("caught exception: " + x); 

so not output out of it. have tried put flags in while loop check whether or not gets into, , gets into. changed encoding in charset.defaultcharset().decode(buf), result : no output. of course there text in file passed newbytechannel(file);

any idea? lot in advance.

**

edit:

** solved, file trying access had been accidentally corrupted. after having changed file, working.

the code looks wrong. try changing rewind() flip(), , flip() compact().


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -