java - PushBackInputStream and DataInputStream, how to push back a double? -


if want read ahead byte,and push if not '<',i can this:

pushbackinputstream pbin=new pushbackinputstream(new fileinputstream("1.dat")); int b = pbin.read(); if(b!='<')     pbin.unread(b); 

but if want push double read datainputstream,what shall do? example:

pushbackinputstream pbin1=null; datainputstream din=new datainputstream(             pbin1=new pushbackinputstream(                         new fileinputstream("1.dat")                     )         ); double d = din.readdouble(); pbin1.unread(d); 

the last line pbin1.unread(d); can not compiled,because pushbackinputstream can not push double,how can convent double byte array?or other way?

you can't push double way. method datainputstream.readdouble() reads 8 bytes create double, can't pass double pushbackinputstream.unread() , expect him know how deal with.

to achieve want solution simple:

pushbackinputstream pbin1=new pushbackinputstream(new fileinputstream("1.dat")); datainputstream din=new datainputstream(pbin1);  double d = din.readdouble(); // double out of stream byte[] doubleasbytes = new byte[8]; bytebuffer.wrap(doubleasbytes).putdouble(d); // transform double byte representation pbin1.unread(bytes); // push bytes 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -