• 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

Writing byte[ ] to a file

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all, i am having problems. I am reading bytes from a queue(mq series) and trying to simply write the bytes out to a .dat file, it is creating the file but it is empty. I'm not to good at Java IO so I need help - what am i doing wrong??
thanks , here is the code:
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure that your array b has any elements? Why don't you try printing out the contents of the array via println() or the length immeiately after you have called message.readFully(b);
Also, try flushing the cache before you call message.clearMessage()
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, are you sure the file is really empty? It's possible that it's filled with NULL chars (value 0) and you're looking at it with a viewer that makes it look like nothing's there. Double-check the size of the file, as well as the array size as Rob suggests.
Also as suggested by Barry in another thread, call bos.close() at the end. (The flush() call should have the same basic effect for our purposes, but maybe not...)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic