Example #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("测试***************");
            CreateFileConfig config = new CreateFileConfig()
            {
                IsAsync = true, CreateUrl = "D:\\Desktop\\A.txt"
            };
            CopyFileConfig copyFileConfig = new CopyFileConfig(true, "D:\\Desktop\\A.txt", "D:\\Desktop\\B.txt");

            UpFileSingleTest.Create(config);
            UpFileSingleTest.Copy(copyFileConfig);
            UpFileSingleTest.CopyBigFile("E:\\电影\\捉丶妖丶记 HD1080P.mp4", "D:\\Desktop\\2.mp4", 10, 1024 * 100);
            Console.WriteLine("完成");
            Console.Read();
        }
 /// <summary>
 /// 根据配置需求,创建文件
 /// </summary>
 /// <param name="config"></param>
 public static void Create(IFileConfig config)
 {
     lock (_lockObj)
     {
         CreateFileConfig createFileConfig = config as CreateFileConfig;
         if (createFileConfig == null)
         {
             return;
         }
         if (createFileConfig.CreateUrl == null)
         {
             return;
         }
         char[]     insertContent    = "HelloWorld".ToCharArray();
         byte[]     byteArrayContent = Encoding.Default.GetBytes(insertContent);
         FileStream stream           = createFileConfig.IsAsync
             ? new FileStream(createFileConfig.CreateUrl, FileMode.Create, FileAccess.ReadWrite, FileShare.Read,
                              4096, true)
             : new FileStream(createFileConfig.CreateUrl, FileMode.Create);
         using (stream)
         {
             if (stream.CanWrite)
             {
                 if (!stream.IsAsync)
                 {
                     stream.Write(byteArrayContent, 0, byteArrayContent.Length);
                     Console.WriteLine($"同步创建文件地址{stream.Name}");
                 }
                 else
                 {
                     stream.BeginWrite(byteArrayContent, 0, byteArrayContent.Length, EndCreateFileCallBack, stream);
                 }
             }
         }
     }
 }