zoukankan      html  css  js  c++  java
  • File操作

    对文件进行操作(只操作小文件)

    bool Exists(string path)  判断文件是否存在

    FileStream Create(string path)  创建文件

    void Move(string sourcePath,string destPath)  剪切文件

    void Copy(string sourcePath,string destPath)  复制文件(destPath不能是目录或现有文件)

    if (!File.Exists(@"D:UsersDesktopStudy.txt"))
                {
                    File.Create(@"D:UsersDesktopStudy.txt");
                }
                File.Move(@"D:UsersDesktopStudy.txt", @"D:StudyUp.txt");
                File.Copy(@"D:StudyUp.txt", @"D:UsersDesktopStudyTwo.txt");
                File.Delete(@"D:StudyUp.txt");
                File.Delete(@"D:UsersDesktopStudyTwo.txt");

    string[] ReadAllLines()  逐行读取文本

    //ReadAllLines()默认采用的编码格式是utf-8
    string[] str=File.ReadAllLines(@"D:UsersdesktopStudy.txt",Encoding,Default);

    string ReadAllText()  读取文本

    //ReadAllText()默认采用的编码格式是utf-8
    string str=File.ReadAllText(@"D:UsersdesktopStudy.txt");

    byte[] ReadAllBytes()  读取文本

    byte[] buffer=File.ReadAllBytes(@"D:UsersdesktopStudy.txt");
    //字节数组--->字符串
    string str = Encoding.UTF-8.GetString(buffer);
    //如果转成gbk
    string strGBK = Encoding.GetEncoding("gbk").GetString(buffer);

    void WriteAllBytes()  以字节写入文本

    string num="一二三四五六七八九十";
    //字符串--->字节数组
    byte[] buffer=Encoding.Default.GetBytes(num);
    File.WriteAllBytes(@"D:UsersdesktopStudy.txt",buffer);

    void WriteAllLines()   以行的形式写入文本

    File.WriteAllLines(@"D:UsersdesktopStudy.txt",new string[]{"",""});

    void WriteAllText()   以字符串的形式写入文本

    File.WriteAllText(@"D:UsersdesktopStudy.txt","乱七八糟");
  • 相关阅读:
    [转]Convolution Neural Network (CNN) 原理与实现
    [转]深度学习CNN研究反向
    [转]一张图看懂:Google AlphaGo的原理、弱点
    [转]前馈型神经网络与反馈型神经网络的区别
    [转]认知机和神经认知机
    [转]技术向:一文读懂卷积神经网络CNN
    PHP 日期格式化 参数参考
    PHP MAIL DEMO(程序代码直接发送邮件)
    PHP上传文件DEMO
    PDO事务管理DEMO
  • 原文地址:https://www.cnblogs.com/xiaonangua/p/7299670.html
Copyright © 2011-2022 走看看