Reading an array of byte...
Hi guys,
i'm a problem and i need your help for solving it.
I've developed a java application that read a txt file and coded it into an array of byte.
My original file has tree rows
string string string string.....(string...string...)
string double double ...(double....double)
string double double....(double...double...)
I've coded this file with this function in an array of bytes,putting whitespace(in byte) beetwen two different value and ;(in byte) for indicate end of row.
My problem is:
If i use in main
String lettura=new String(x);
System.out.println("La stringa di lettura e'"+lettura);
where x is the array of byte i see this
La stringa di lettura e'ProbesetID MAO.CEL MAO1.CEL MAO2.CEL MAM.CEL MAM1.CEL MAM2.CEL ZAR.CEL ZOR.CEL ZOR1.CEL ZOE.CEL ZOE1.CEL ZOE2.CEL ;1007_s_at 2 5 2 7 . 5 1 5 5 7 2 ;2 7 4 5 . 4 2 7 6 1 3 ;2 7 2 1 . 7 4 4 0 9 1 ;1 4 1 8 . 3 7 4 2 6 1 ;1 4 1 4 . 6 4 5 2 9 ;1 3 6 2 . 3 4 1 0 0 6 ;2 4 4 7 . 8 1 2 2 1 ;2 3 4 0 . 5 5 2 6 5 7 ;2 3 3 5 . 3 8 3 6 4 1 ;1 3 0 1 . 8 3 1 6 5 3 ;1 3 4 3 . 2 0 1 4 0 3 ;1 3 0 5 . 5 7 4 0 2 3
that is my original file but the doubles are saw as characters,so 2527.515572 became 2 5 2 7 . 5 1 5 5 7 2.
How can i print these numbers as a double?
Can you help me with some code lines that format my string,creating a new line for each ;and a double for the characters?
Thanks very much i've posted also my conversion function:
The function used is:
publicbyte[] getBytes(){
byte middlerow=' ';
byte endrow=';';
byte[] data=null;
Vector temp=new Vector(100000);
int i=0;
String g=null;
Riga r;
Double val[];
while(i<intest.length){
byte[] bytesnew=intest[i].getBytes();
//temp.addAll(bytesnew);
//memorizza in byte un elemento del vettore alla volta
for(byte b : bytesnew) temp.add(new Byte(b));//provare Byte
//temp.addElement(intest[i].getBytes());
temp.addElement(Byte.valueOf(middlerow));
i++;
}
temp.addElement(Byte.valueOf(endrow));
System.out.println("Intestazione convertita in byte");
for(int l=0;l<rows.size()-1;l++){
r=(Riga)rows.get(l);
g=r.getgeneid();
//temp.addElement(g.getBytes());
byte[] byte2=g.getBytes();
for(byte c : byte2) temp.add(new Byte(c));
temp.addElement(Byte.valueOf(middlerow));
val=r.getvalues();
byte[] tempByte1;
for(int e=0;e<=val.length-1;e++){
//Returns a string representation of the double argument.
tempByte1 = Double.toString(val[e]).getBytes();
for (int j = 0; j >< tempByte1.length; j++){
temp.addElement(Byte.valueOf(tempByte1[j]));
temp.addElement(Byte.valueOf(middlerow));
}
temp.addElement(Byte.valueOf(endrow));
}
}
data=newbyte[temp.size()];
for (int t=0;t<temp.size()-1;t++)
data[t]=(((Byte)temp.elementAt(t)).byteValue());
return data;
}
>

