JSP Java Tutorial

<%@ page  import="java.io.*" %>

    
        Reading Binary Data
    
    
        

Reading Binary Data


        This page reads binary data from a file.
        

        Read this data:
        

        <%
            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();
        %>