zoukankan      html  css  js  c++  java
  • 文件操作

       static void Main(string[] args)
            {
                XmlDocument doc = new XmlDocument();
                doc.Load("./XML.xml");
    
                XmlElement rootElement = null;
    
                XmlNodeList nodeList = doc.SelectNodes("bookstore/book/title");
    
                foreach (XmlNode itemNode in nodeList)
                {
                    Console.WriteLine(itemNode.InnerText);
                }
    
    
                rootElement = doc.DocumentElement;
    
                XmlNodeList bookNodeList = rootElement.SelectNodes("book");
    
                foreach (XmlNode xmlnode in bookNodeList)
                {
                    if (!xmlnode.HasChildNodes)
                    {
                        Console.WriteLine(xmlnode.InnerText);
                    }
                    else
                    {
                        XmlNode titlenode = xmlnode.SelectSingleNode("title");
                        Console.WriteLine(titlenode.InnerText);
    
                    }
                }
    
                Console.ReadLine();






     class FileDemo
        {
            //public static void Main(string[] args)
            //{
            //    string path = @"d:1.txt";
            //    string content = "www.zklve.com" + DateTime.Now.ToString();
            //    if (Directory.Exists(path))
            //    {
            //        Directory.CreateDirectory(path);
            //    }
    
            //    //写入文件内容
            //    File.WriteAllText(path, content);
    
            //    //文件copy              
            //    string sourcePath = @"d:2.zip";
            //    string desPath = @"e:2.zip";
            //    File.Copy(sourcePath, desPath);
            //}


         public static void Main()
            {
                string[] strArr = new string[5] { "1", "1", "1", "1", "1", };
    
                string path = @"d:2.zip";
    
                //要写入的流
                Stream s = new FileStream(path, FileMode.Open);
                byte[] butter = new byte[s.Length];//缓冲区
                s.Read(butter, 0, butter.Length);//读取工作
    
                //写入准备
                string desPath = @"e:3.zip";
                FileStream fs = new FileStream(desPath, FileMode.Create);
                fs.Write(butter,0,butter.Length);
                fs.Flush();
                fs.Close();
                s.Flush();
                s.Close();
    
    
    

      





    
    
    
     
  • 相关阅读:
    向eureka注册正确的ip地址
    sleuth + zipkin 链路分析
    Yii2的整体结构概览
    Redis实现消息队列
    Redis使用场景梳理
    redis基础知识
    TCP服务
    数据结构-队列
    看见
    线性表的链式存储结构
  • 原文地址:https://www.cnblogs.com/kunlunmountain/p/5141727.html
Copyright © 2011-2022 走看看