Java/JSP/File Binary Write

Материал из Java эксперт
Перейти к: навигация, поиск

File: Writing Binary Data

<%@ page import="java.io.*" %>
<HTML>
    <HEAD>
        <TITLE>Writing Binary Data</TITLE>
    </HEAD>
    <BODY>
        <H1>Writing Binary Data</H1>
        This page writes binary data to a file.
        <BR>
        <%
            byte data[] = {1, 2, 3, 4};
            String file = application.getRealPath("/") + "file.dat";
            FileOutputStream fileoutputstream = new FileOutputStream(file);
            for (int i = 0; i < data.length; i++) {
                fileoutputstream.write(data[i]);
            }
            fileoutputstream.close();
        %>
        Four byte values were written to a file byte by byte.
    </BODY>
</HTML>