I'm doing a program that needs to read a binary file and go extracting some information from it, what I have so far is this:
public void processarArquivo() throws Exception{
try {
FileInputStream fileInputStream = new FileInputStream(ARQUIVO DE ENTRADA);
BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
DataInputStream objectIn = new DataInputStream(bufferedInputStream);
while (objectIn != null)
{
try {
String data = objectIn.readUTF();
char[]direcaoVento = objectIn.readChar();
int velocidadeVento = objectIn.readInt();
int indicePluviometrico = objectIn.readInt();
float temperatura = objectIn.readFloat();
}
catch(IOException e){
objectIn.close();
objectIn = null;
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
The mirror of my file is this:
Espelho do arquivo DadosMeteorologicos-Exemplo.dat
10/10/2015-E -1-15-19.8
11/10/2015-SE-38-16-15.1
12/10/2015-NW-69-4-15.6
13/10/2015-W -9-3-18.1
14/10/2015-NE-11-14-27.8
15/10/2015-SW-51-0-28.7
16/10/2015-NW-24-0-17.8
17/10/2015-E -11-12-16.1
18/10/2015-E -35-0-26.2
19/10/2015-W -42-8-15.8
20/10/2015-SE-14-17-21.7
21/10/2015-NW-51-0-26.0
22/10/2015-E -37-0-25.2
23/10/2015-SW-9-15-26.1
24/10/2015-NE-2-16-21.9
My question concerns while, is there any way to check when I get to the end of the objectIn? Currently I just have while (true)
and I expect the program to fire a Exception
. But that seems wrong to me anyway.