• 文件操作


       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();
    
    
    

      





    
    
    
     
  • 相关阅读:
    jquery跨域3
    juery的跨域请求2
    jquery的跨域请求
    synchronized与Lock的区别
    springboot之启动原理解析及源码阅读
    java中Number类理解
    springboot中配置文件application.properties的理解
    restTemplate设置访问超时
    BigDecimal.setScale 处理java小数点
    NIO之FileChannel类的理解和使用
  • 原文地址:https://www.cnblogs.com/kunlunmountain/p/5141727.html
Copyright © 2020-2023  润新知