[HttpPost]
public void PostMember()
{
HttpPostedFile file = null//定义文件接收类
//如果有其他参数,下面的示例接收数据
//var openid = HttpContext.Current.Request.Form["openid"]
foreach (string item in HttpContext.Current.Request.Files)
{
file = HttpContext.Current.Request.Files[item]
}
if (file == null || openid == null)
{
throw new Exception("文件不存在")
}
string openpath = HttpContext.Current.Server.MapPath("~/video/" + openid + "/")
string fileName = DateTime.Now.ToFileTime() + ".mp3"
string sourepath = openpath + fileName
file.SaveAs(sourepath)
//至于怎么把这个地址存到库里,我就不写了,因为每个人都有不同的业务逻辑
}
java将byte数组转换成图片,可以File和IO *** 作来完成,实例如下:
//byte数组到图片到硬盘上public void byte2image(byte[] data,String path){
if(data.length<3||path.equals("")) return//判断输入的byte是否为空
try{
FileImageOutputStream imageOutput = new FileImageOutputStream(new File(path))//打开输入流
imageOutput.write(data, 0, data.length)//将byte写入硬盘
imageOutput.close()
System.out.println("Make Picture success,Please find image in " + path)
} catch(Exception ex) {
System.out.println("Exception: " + ex)
ex.printStackTrace()
}
}
1、读取文件,并转换为字节流:FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read)
byte[] infbytes = new byte[(int)fs.Length]
fs.Read(infbytes, 0, infbytes.Length)
fs.Close()
return infbytes
2、将字节流写入文件
FileStream fs = new FileStream("D:\\inf.dlv", FileMode.Create, FileAccess.Write)
fs.Write(inf, 0, inf.Length)
fs.Close()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)