Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
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:
Java in General
write array of bytes to a file
roy williams
Greenhorn
Posts: 10
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hello all, i am having problems. I am trying to simply write the array 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:
File f2 = new File("writeQdata.txt"); try { BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(f2)); ** b[ ]the array has 131072 bytes bos.write(b, 0, b.length); bos.flush(); } catch (IOException e) { ...
Malcolm Featonby
Greenhorn
Posts: 14
posted 20 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
No idea I am afraid, I tried it and it workds fine???
import java.io.*; public class sample { private byte[] b=new byte[131072]; public sample() { byte aByte; for (int i = 0; i < b.length; i++) { b[i] = (byte)((Math.random() * 255) - 128); } File f2 = new File("writeQdata.txt"); try { BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(f2)); //** b[ ]the array has 131072 bytes bos.write(b, 0, b.length); bos.flush(); //bos.close(); } catch (IOException e) { System.out.println("IOException occured: " + e.getMessage()); } } public static void main(String[] args) { sample thisClass = new sample(); } }
Are you sure this is a full excerpt from your code ?
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Cannot Figure Out This Syntax Error
FTP with sun.net.ftp.
Using Apache Commons Codec
write byte array to a file
Writing byte[ ] to a file
More...