zoukankan      html  css  js  c++  java
  • C# 读取本地图片 转存到其他盘符

    UpFileContent upfile = new UpFileContent();
    upfile.StationImageName = "123.png";
    FileStream fs = new FileStream(@"E:123.jpg", FileMode.Open, FileAccess.Read);
    Byte[] btye2 = new byte[fs.Length];
    fs.Read(btye2, 0, Convert.ToInt32(fs.Length));
    fs.Close();
    upfile.ImageContent = btye2;


    Stream sourceStream = new MemoryStream(upfile.ImageContent);
    FileStream targetStream = null;
    if (!sourceStream.CanRead)
    {
    throw new Exception("");
    }

    string DiskName = @"d:";
    string FileAddress = @"ProductImagesSmall";
    string LocationAddress = DiskName + FileAddress;

    if (!Directory.Exists(LocationAddress))
    {
    Directory.CreateDirectory(LocationAddress);
    }
    string filePath = Path.Combine(LocationAddress, upfile.StationImageName);
    using (targetStream = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write))
    {
    int count = 0;
    const int bufferlength = 4096;
    byte[] buffer = new byte[bufferlength];
    while ((count = sourceStream.Read(buffer, 0, bufferlength)) > 0)
    {
    targetStream.Write(buffer, 0, count);
    }
    targetStream.Close();
    sourceStream.Close();
    IsSuccess = true;
    }

  • 相关阅读:
    Java8新特性3 Stream
    注解
    Base64编码
    代理
    Cglib
    快照
    Java安全模式
    Hibernet缓存详解
    中文文档
    JDK1.8时间日期函数
  • 原文地址:https://www.cnblogs.com/androllen/p/3453309.html
Copyright © 2011-2022 走看看