static void Main(string[] args) { Console.SetOut(new MyWrite()); #region 常规文件 var filer = FileHelp.Set("HTMLPage.html"); var myStream = filer.ReadByMemoryStream(); filer.StreamSave(myStream); var fileinfo = filer.GetFileInfo(); fileinfo.CopyTo("new.html", true); filer.Append("aaaa").AppendLineAsJson(new { a = 1, b = 2, c = 3 }).SaveAppend(); #endregion #region 图片文件处理 var fileImg = FileHelp.Set("20.jpg"); var ms = fileImg.ReadByMemoryStream(); Image img = Image.FromStream(ms); var letterImg = ImageHelper.LetterWatermark("20.jpg", 14, "中华人民共和国", Color.Red, "T"); Console.WriteLine("{0} 增加水印成功.", letterImg); //生成缩略图 var newImg = ImageHelper.MakeThumbnail(img, 50, 50, ThumbnailModel.Auto); newImg.Save("newImg.png", ImageFormat.Png); ms.Close(); #endregion #region 文件夹处理 var allDir = DirectoryHelp.GetAllDirInfo("Log").ToList(); Console.WriteLine(DirectoryHelp.Combine("aaa", "ddd.txt")); foreach (DriveInfo drive in DirectoryHelp.GetAllDrives()) { if (drive.IsReady) { Console.WriteLine("类型:{0} 卷标:{1} 名称:{2} 总空间:{3} 剩余空间:{4}", drive.DriveType, drive.VolumeLabel, drive.Name, drive.TotalSize, drive.TotalFreeSpace); } else { Console.WriteLine("类型:{0} 状态:没有准备好", drive.DriveType); } } #endregion Console.ReadKey(); }
/// <summary> /// 读取字节指定长度转换为 字符串 /// </summary> /// <param name="bytes">字节</param> /// <param name="offset">读取的开始位</param> /// <param name="count">总共获取长度</param> /// <returns></returns> public static string ReadByString(byte[] bytes, int offset, int count) { var readbytes = FileHelp.BytesCopy(bytes, offset, count); return(Encoding.Default.GetString(readbytes)); }