zoukankan      html  css  js  c++  java
  • 使用文件流,读写网络共享盘

    新建一个.NET Core控制台项目,使用文件流读写网络共享盘文件,如下所示:

    using System;
    using System.IO;
    using System.Text;
    
    namespace NetCoreShareFolderReading
    {
        class Program
        {
            static void Main(string[] args)
            {
                string path = @"\192.168.1.150Upload FolderScottDemo.txt";
                string text;
    
                using (FileStream fs = new FileStream(path, FileMode.Open))
                {
                    byte[] data = new byte[fs.Length];
    
                    fs.Read(data, 0, data.Length);
    
                    text = Encoding.ASCII.GetString(data);
                }
    
                Console.WriteLine(text);
    
                path = @"\192.168.1.150Upload FolderScott测试文件.txt";
    
                using (StreamReader sr = new StreamReader(path, Encoding.UTF8))
                {
                    text = sr.ReadToEnd();
                }
    
                Console.WriteLine(text);
    
                path = @"\192.168.1.150Upload FolderScott测试文件_写回.txt";
    
                using (StreamWriter sw = new StreamWriter(path, false, Encoding.UTF8))
                {
                    sw.Write("这是使用C#写入的文件内容,Good day guys~12345678");
                }
    
                Console.WriteLine("Press any key to end...");
                Console.ReadKey();
            }
        }
    }

    可以看到使用文件流读写网络共享盘文件,和读写本地磁盘文件一样。

  • 相关阅读:
    SSM简单实现文件上传和下载
    Web发送邮件
    scala写算法-快排
    scala写算法-从后缀表达式构造
    scalajs_初体验
    scala写算法-用小根堆解决topK
    scala-Future和Promise
    python基础之函数
    python基础知识(五)
    python基础知识(四)
  • 原文地址:https://www.cnblogs.com/OpenCoder/p/12897660.html
Copyright © 2011-2022 走看看