Reading an array of byte with special delimiter....help me!!

G

gbattine

Hi guys,
i've developed a java application that has in input a txt file with a
standard format

string string string
string double double
string double double

and stores it into an array of byte with a fixed format,
that is
byte(whitespace)byte(whitespace)byte(;)byte(whitespace)byte(whitespace)byte(;)byte(whitespace)byte(whitespace)byte(;)


that mean introducing byte whitespace value and byte ; value to
separate different columns and different rows.
Now i have to develop inverse routine,that has to read the array of
byte and rebuild its original format.
Can you help me with some idea ord code?
I'm inexepert...please help me with clear suggest...
I post you my routine that converts txt file into an array of byte
P.S.In my txt file number of columns and rows change for each file,what
is standard is a firtst headline that is an array of string and others
row with the same format string array of doubles....

Code:
public byte[] getBytes(){
byte middlerow=' ';
byte endrow=';';
Vector temp=new Vector(10000000);
int i=0;
String g=null;
Riga r;
Double val[];
while(i<intest.length){
//copio tutto nell'array di byte
byte []bytes = intest[i].getBytes();
//			memorizza in byte un elemento del vettore alla volta
for( Byte aByte : bytes ) {
temp.addElement( aByte );


}


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());
temp.addElement(Byte.valueOf(middlerow));
val=r.getvalues();


for(int e=0;e<=val.length-1;e++){


temp.addElement(Byte.valueOf(val[e].byteValue()));
//val[e].byteValue() fa il casting double in byte
temp.addElement(Byte.valueOf(middlerow));
}
temp.addElement(Byte.valueOf(endrow));

}



byte [] b=new byte[temp.size()];

for (int k=0;i<temp.size();i++){
b[k]=(((Byte)temp.elementAt(k)).byteValue());
}
return b;


}

Thanks for your help...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top