<%@ page import="java.io.*" %>
<HTML>
<HEAD>
<TITLE>Reading Binary Data</TITLE>
</HEAD>
<BODY>
<H1>Reading Binary Data</H1>
This page reads binary data from a file.
<BR>
Read this data:
<BR>
<BR>
<%
String file = application.getRealPath("/") + "test.dat";
double data[] = {1.234, 2.345, 3.456, 4.567};
FileOutputStream fileoutputstream = new FileOutputStream(file);
ObjectOutputStream objectStream = new ObjectOutputStream(fileoutputstream );
for (int i = 0; i < data.length; i++) {
objectStream.writeDouble(data[i]);
}
objectStream.close();
FileInputStream fileinputstream = new FileInputStream(file);
ObjectInputStream inputobjectStream = new ObjectInputStream(fileinputstream);
for(int i = 0; i < 4; i++){
double d = inputobjectStream.readDouble();
out.println(d);
}
objectStream.close();
%>
</BODY>
</HTML>
|