Lecture erronée de float dans un fichier binaire
Bonjour,
J'ai un fichier binaire contenant des float que je peux lire sans problème avec le code C++ suivant:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
template<typename T>
std::istream & read(std::istream& is, T& value) {
return is.read(reinterpret_cast<char*> (&value), sizeof (T));
}
int main(int argc, char** argv) {
std::ifstream FileIn("conc1.out", std::ios_base::binary);
float xin;
for (int i = 0; i < 2230; i++) {
read(FileIn, xin);
std::cout << xin << " ";
}
cout << endl;
FileIn.close();
return 0;
} |
J'ai le code suivant en JAVA:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
public static void main(String[] args) {
// TODO code application logic here
FileInputStream fis = null;
try {
fis = new FileInputStream("Y:\\Hydrus_2D\\ONDRAF_2D_safety_model\\Boundary_conditions\\Flow\\average\\conc1.out");
DataInputStream dis = new DataInputStream(fis);
try {
for (int i = 0; i < 2230; i++) {
System.out.print(Float.intBitsToFloat(dis.readInt()) + " ");
if (i % 100 == 0) {
System.out.println();
}
}
} finally {
if (fis != null) {
fis.close();
}
}
} catch (IOException ioe) {
System.out.println("IOException");
}
} |
Et je n'obtiens pas les valeurs numériques escomptées alors que le code C++ fonctionne sans problème.
Avez-vous une solution?
Cordialement,
Bou