Eu tô com um duvida… eu tenho um código que escreve em um arquivo… aqui está o método onde escrevo:
public void writing () throws FileNotFoundException, IOException{
DataOutputStream dos = new DataOutputStream(new FileOutputStream("C:\Users\Desktop\demo16.map"));
dos.writeShort(vers); // escrevi 307
dos.writeChars(name); // escrevi porto de galinhas
dos.writeShort(ano); // escrevi 1989
dos.writeByte(mes); // escrevi 08 ... e assim sucessivamente
dos.writeByte(dia);
dos.writeShort(15); //
dos.writeShort(15); //
dos.writeShort(defs);
dos.writeInt(topLat);
dos.writeInt(botLat);
for(int i=0; i<MAXDEFS;i++){
if(i<defLons.length){
dos.writeInt(defLons[i]);
}
else{
dos.writeInt((0));
}
}//end for
for(int i=0;i<MAXDEFS;i++){
if(i<topDefX.length){
dos.writeShort(topDefX[i]);
}
else{
dos.writeShort(0);
}
}//end for
for(int i=0; i<MAXDEFS;i++){
if(i<topDefY.length){
dos.writeShort(topDefY[i]);
}
else{
dos.writeShort(0);
}
}//end for
for(int i=0; i<MAXDEFS;i++){
if(i<botDefX.length){
dos.writeShort(botDefX[i]);
}
else{
dos.writeShort(0);
}
}//end for
for(int i=0; i<MAXDEFS;i++){
if(i<botDefY.length){
dos.writeShort(botDefY[i]);
}
else{
dos.writeShort(0);
}
}//end for
dos.writeInt(mapWidth << 16);
dos.writeInt(mapHeight << 16);
for(int i=0; i<256;i++){
if(i<127){
dos.writeByte(r[i]);
dos.writeByte(g[i]);
dos.writeByte(b[i]);
}
else{
dos.writeByte(0);
}
}//end for
dos.write(vetorU);
dos.close();
}
Mas agora eu tenho um outro programa q deve ler esses dados, soh q ele está lendo coisas que não tem nada a ver como o eu escrevi…
Aqui está parte do médoto dele:
public void test(File f) throws FileNotFoundException, IOException{
RandomAccessFile fis = new RandomAccessFile(f,"r");
vers=readThisShort(fis);
System.out.println("Version "+ vers);// imprimiu 13057
name=readThisString(fis,15);
System.out.println("Name "+ name); // imprimiu: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
ano=readThisShort(fis);
mes=readThisByte(fis);
dia=readThisByte(fis);
System.out.println("Date "+ dia+"."+mes+"."+ano); // imprimiu: Date 82.0.8192
kind=readThisShort(fis);
System.out.println("Kind "+ kind);// imprimiu: Kind 17664
group=readThisWord(fis);
System.out.println("Group "+ group);
dfs=readThisShort(fis);
System.out.println("DFS "+ dfs);
topLat=readThisInt(fis);
System.out.println("TopLat "+ topLat);
botLat=readThisInt(fis);
System.out.println("BotLat"+ botLat);
defLons=readThisArrayInt(fis);
System.out.println("defLons:");
for(int i=0; i<defLons.length;i++){
System.out.println(defLons[i]);
}
topdefx=readThisArrayShort(fis);
System.out.println("topdefx:");
for(int i=0; i<topdefx.length;i++){
System.out.println(topdefx[i]);
}
topdefy=readThisArrayShort(fis);
System.out.println("topdefy:");
for(int i=0; i<topdefy.length;i++){
System.out.println(topdefy[i]);
}
botdefx=readThisArrayShort(fis);
System.out.println("botdefx:");
for(int i=0; i<botdefx.length;i++){
System.out.println(botdefx[i]);
}
botdefy=readThisArrayShort(fis);
System.out.println("botdefy:");
for(int i=0; i<botdefy.length;i++){
System.out.println(botdefy[i]);
}
mapWidth=readThisWord(fis);
System.out.println("Width "+ mapWidth);
mapHeight=readThisWord(fis);
System.out.println("Height "+ mapHeight);
}
Ou seja está lendo tudo errado… alguém sabe o q pode estar acontecendo?