zoukankan      html  css  js  c++  java
  • 读写二进制c# 二进制读写

    最近使用开发的过程中出现了一个小问题,顺便记录一下原因和方法--读写二进制

        using System;

        using System.IO;

        class MyStream

        {

        private const string FILE_NAME = "Test.data";

        public static void Main(String[] args)

        {

        // Create the new, empty data file.

        if (File.Exists(FILE_NAME))

        {

        Console.WriteLine("{0} already exists!", FILE_NAME);

        return;

        }

        FileStream fs = new FileStream(FILE_NAME, FileMode.CreateNew);

        // Create the writer for data.

        每日一道理
    父亲对于儿子来说,是座耸立的高山,而儿子只是颗石子,源于山,却并不了解山。生活中诸多爱的密码,是需用细节来解读的,在亲情的沃土上,要想搞得最美的果实,惟有期待那存在于瞬间的心与心的共鸣,爱与爱的默契。

        BinaryWriter w = new BinaryWriter(fs);

        // Write data to Test.data.

        for (int i = 0; i < 11; i++)

        {

        w.Write( (int) i);

        }

        w.Close();

        fs.Close();

        // Create the reader for data.

        fs = new FileStream(FILE_NAME, FileMode.Open, FileAccess.Read);

        BinaryReader r = new BinaryReader(fs);

        // Read data from Test.data.

        for (int i = 0; i < 11; i++)

        {

        Console.WriteLine(r.ReadInt32());

        }

        w.Close();

        }

        }

    文章结束给大家分享下程序员的一些笑话语录: 程序员打油诗   
      写字楼里写字间,写字间里程序员;
      程序人员写程序,又拿程序换酒钱。
      酒醒只在网上坐,酒醉还来网下眠;
      酒醉酒醒日复日,网上网下年复年。
      但愿老死电脑间,不愿鞠躬老板前;
      奔驰宝马贵者趣,公交自行程序员。
      别人笑我忒疯癫,我笑自己命太贱;
      不见满街漂亮妹,哪个归得程序员。

    --------------------------------- 原创文章 By
    data和class
    ---------------------------------

  • 相关阅读:
    通过IP地址和子网掩码与运算计算相关地址
    IP地址与子网掩码的计算
    win10用键盘控制鼠标
    requirements.txt
    vue中axios使用二:axios以post,get,jsonp的方式请求后台数据
    vue中axios使用一:axios做拦截器
    git切换分支冲突解决-删除分支
    获取指定月份前的第一天和最后一天及两个日期之间的月份列表
    git远程版本回退
    git Please move or remove them before you can merge
  • 原文地址:https://www.cnblogs.com/xinyuyuanm/p/3104878.html
Copyright © 2011-2022 走看看