S
sbq
I am writing some 32 bit integer data in matlab using statements such
as:
f=fopen('temp','w');
a=int32(23);
fprintf(f,'%d',a);
fclose(f);
and trying to read in in JAVA using:
public static void main(String[] args) {
// TODO code application logic here
File file = new File("C:\\JAVA\\temp");
FileInputStream fis = null;
BufferedInputStream bis = null;
DataInputStream dis = null;
try {
fis = new FileInputStream(file);
// Here BufferedInputStream is added for fast reading.
bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
int a;
a = dis.readInt();
System.out.print(a);
// dispose all the resources after using them.
fis.close();
bis.close();
dis.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}//end catch2
}//end main
======================
Now logically, reading a 32 bit integer using this command should work
fine, but I am getting out of range values, like, if i am just reading
in integer valued 32, it would rather print 8924558 or something like
that, garbage values. I have tried using read other reading methods as
well such as readByte, readShort, read etc but only thing that works
is readln, which I don't want. It brings in whole line of data, which
i don't want. Rather, I need individual integers to be read, perhaps
delimited by tabs or new lines
as:
f=fopen('temp','w');
a=int32(23);
fprintf(f,'%d',a);
fclose(f);
and trying to read in in JAVA using:
public static void main(String[] args) {
// TODO code application logic here
File file = new File("C:\\JAVA\\temp");
FileInputStream fis = null;
BufferedInputStream bis = null;
DataInputStream dis = null;
try {
fis = new FileInputStream(file);
// Here BufferedInputStream is added for fast reading.
bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
int a;
a = dis.readInt();
System.out.print(a);
// dispose all the resources after using them.
fis.close();
bis.close();
dis.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}//end catch2
}//end main
======================
Now logically, reading a 32 bit integer using this command should work
fine, but I am getting out of range values, like, if i am just reading
in integer valued 32, it would rather print 8924558 or something like
that, garbage values. I have tried using read other reading methods as
well such as readByte, readShort, read etc but only thing that works
is readln, which I don't want. It brings in whole line of data, which
i don't want. Rather, I need individual integers to be read, perhaps
delimited by tabs or new lines