zoukankan      html  css  js  c++  java
  • Read and write flat file

     private void operateFlatFile()
    {
        string path;
        FileStream fs;
        byte[] _read, _write;
        int start, end;

        start = 0;
        end = 50;

        // read
        path = Server.MapPath("http://www.cnblogs.com/document/encode.txt");
        fs = new FileStream(path, FileMode.Open);
        _read = new byte[end];

        fs.Read(_read, start, end);
        fs.Close();

        // print
        Encoding ur = Encoding.GetEncoding("gb2312");
        string content = ur.GetString(_read);
        Response.Write(content + "<br>");

        // write
        path = Server.MapPath("http://www.cnblogs.com/document/new.txt");
        fs = new FileStream(path, FileMode.OpenOrCreate) ;

        Encoding uw = Encoding.GetEncoding("utf-8") ;
        _write = uw.GetBytes(content);

        fs.Write(_write, start, _write.Length);
        fs.Close();

        // show message

        Response.Write( "succ.");
    }

  • 相关阅读:
    小球与盒子的故事
    2020.1.11 考试总结
    P4249 [WC2007]剪刀石头布
    P3825 [NOI2017]游戏
    BZOJ 2238 Mst
    P4240 毒瘤之神的考验
    生成函数(严重残缺)
    Min_25
    P3455 [POI2007]ZAP-Queries
    P3233 [HNOI2014]世界树
  • 原文地址:https://www.cnblogs.com/aspsmile/p/790823.html
Copyright © 2011-2022 走看看