Reading and writing binary data (C#) : Binary « File Directory « ASP.NET Tutorial






<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        BinaryWriter binarywriter = new BinaryWriter(File.Create(@"Data.dat"));
        binarywriter.Write("a string");
        binarywriter.Write(0x12346789abcdef);
        binarywriter.Write(0x12345678);
        binarywriter.Write('c');
        binarywriter.Write(1.5f);
        binarywriter.Write(100.2m);
        binarywriter.Close();

        BinaryReader binaryreader = new BinaryReader(File.Open(@"Data.dat", FileMode.Open));

        string a = binaryreader.ReadString();
        long l = binaryreader.ReadInt64();
        int i = binaryreader.ReadInt32();
        char c = binaryreader.ReadChar();
        float f = binaryreader.ReadSingle();
        decimal d = binaryreader.ReadDecimal();
        binaryreader.Close();

    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    </form>
</body>
</html>








10.11.Binary
10.11.1.Reading and writing binary data (C#)
10.11.2.Reading and writing binary data (VB)