For Programmers: Free Programming Magazines  


Home > Archive > Java Help > August 2007 > How to convert int/float etc into byte?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to convert int/float etc into byte?
RC

2007-08-24, 7:18 pm

For example

int i = 2;
char c = 'c';
float f = (float)3.45;
double d = 3.546;
String s = "Hello";

I want to write all these into a binary file.

In OutputStream, PrintStream classes
they have

write(int byte); and
write(byte[] buffer, int offset, int length);

My question is how do I convert those i,c,f,d,s into
byte[]?

Thank Q in advance!
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com