Muszę odczytać plik który posiada nagłówek oraz dane zapisane w postaci Little Endian 16 bit Intigers.
Próbowałem już ze wszystkich stron atakować ten temat i null :/ próbowałem tak :
DataInputStream dis = null;
String record;
int recCount = 0;
try {
File f = new File("mmm.rec");
FileInputStream fis = new FileInputStream(f);
BufferedInputStream bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
while ((record = dis.readLine()) != null) {
recCount++;
System.out.println(recCount + ": " + record);
// System.out.println(f.length());
}
} catch (IOException e) {
// catch io errors from FileInputStream or readLine()
System.out.println("Uh oh, got an IOException error!" + e.getMessage());
} finally {
// if the file opened okay, make sure we close it
if (dis != null) {
try {
dis.close();
} catch (IOException ioe) {
}
}
}
i nic (odczytuje tylko nagłowek :/ )
i tak
FileChannel fc = new FileInputStream("mmm.rec").getChannel();
ByteBuffer bb = ByteBuffer.allocate(BSIZE).order(ByteOrder.LITTLE_ENDIAN);
fc.read(bb);
bb.flip();
float licz = 0;
while(bb.hasRemaining()){
System.out.println(licz + ":" + bb.allocate);
}
} catch (EOFException e) {
System.err.println("end");
}
to samo
i tak :
File file = new File("mmm.rec");
FileInputStream fis = null;
BufferedInputStream bis = null;
DataInputStream dis = null;
try {
fis = new FileInputStream(file);
String[] linia;
// Here BufferedInputStream is added for fast reading.
bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
// dis.available() returns 0 if the file does not have more lines.
while (dis.available() != 0) {
// this statement reads the line from the file and print it to
// the console.
System.out.println(dis.readLine());
}
// dispose all the resources after using them.
fis.close();
bis.close();
dis.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
i ciągle mi wyskakują jakieś szlaczki :/
Może ja coś pomojam ?
Jeżeli ktoś by mógł mnie naprowadzić na temat...