zoukankan      html  css  js  c++  java
  • using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    namespace filestream
    {
    class Program
    {
    static void Main(string[] args)
    {
    try
    {
    #region FileStream文件流
    //写入
    FileStream fileStream = new FileStream(@"d: est.txt", FileMode.OpenOrCreate);
    fileStream.Position = fileStream.Length;
    byte[] content = Encoding.UTF8.GetBytes("我爱我家");
    fileStream.Write(content, 0, content.Length);
    fileStream.Position = fileStream.Length;
    content = Encoding.UTF8.GetBytes("45");
    fileStream.Write(content, 0, content.Length);
    fileStream.Close();
    //读取
    fileStream = new FileStream(@"d: est.txt", FileMode.Open);
    content = new byte[fileStream.Length];
    fileStream.Read(content, 0, content.Length);
    Console.WriteLine(Encoding.UTF8.GetString(content));
    #endregion

    //#region MemoryStream内存流
    //MemoryStream me = new MemoryStream();
    //Console.WriteLine("初始分配的容量:" + me.Capacity + "初始使用量:" + me.Length);
    //byte[] contents = Encoding.UTF8.GetBytes("我爱我家");
    //me.Write(contents, 0, contents.Length);
    //Console.WriteLine("初始分配的容量:" + me.Capacity + "初始使用量:" + me.Length);
    //#endregion

    FileStream mss = new FileStream(@"dkeygen.exe", FileMode.Open);
    BinaryReader br = new BinaryReader(mss);

    char cha;
    int num;
    double doub;
    string str;
    while (true)
    {
    cha = br.ReadChar();
    num = br.ReadInt32();
    doub = br.ReadDouble();
    str = br.ReadString();
    Console.WriteLine("{0},{1},{2},{2}", cha, num, doub, str);
    }
    }
    catch (Exception)
    {

    throw;
    }
    }
    }
    }

  • 相关阅读:
    【原创】R61509/SPFD5420A驱动调试总结
    [轉貼]程序员需要具备的基本技能
    Entity SQL 说说IN关键字
    细说可空类型 nullable
    C#值类型与引用类型之我见
    解密区域集成服务器
    序列化对象,使用的三种方式:Xml,Binary,Soap
    有时间就买点书
    hdu2680 Choose the best route
    SQLServer 函数类型简要说明
  • 原文地址:https://www.cnblogs.com/TddCoding/p/3355858.html
Copyright © 2011-2022 走看看