Reading Binary Data : File Save Load « JSP « Java Tutorial






<%@ 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>








23.51.File Save Load
23.51.1.Save Form Input to File using JSP
23.51.2.Index of Files
23.51.3.Read file
23.51.4.Writing Binary Data
23.51.5.Reading Binary Data