MVC 返回404,返回图片,流到数组,apk信息
return HttpNotFound();
byte[] buffer0 = QRCode();
return File(buffer0, @"image/jpeg"); // //通过二进制数据的方式 直接返回图片,在线浏览
Image ss = CreateImage("",false,);
MemoryStream ms = new MemoryStream();
ss.Save(ms, ImageFormat.Jpeg);
byte[] buffer = new byte[ms.Length];
ms.Read(buffer, , buffer.Length);
return File(ms.ToArray(), @"image/jpeg"); // //通过二进制数据的方式
//暂无测试
FileStream fs = new FileStream(); MemoryStream ms = new MemoryStream();
img0.Save(ms, ImageFormat.Jpeg);
byte[] buffer = new byte[ms.Length];
ms.Read(buffer, , buffer.Length); //读取数据到字节数组
fs.Read(buffer, , buffer.Length); //读取字节数组到缓冲区
return new FileStreamResult(new FileStream(path, FileMode.Open), "image/jpeg");
//文件的输入流
Stream filestrem = file.InputStream;
StreamReader sr = new StreamReader(filestrem, System.Text.Encoding.GetEncoding("gb2312"));
string stringReader = sr.ReadToEnd();
StreamReader sr = new StreamReader(filestrem, System.Text.Encoding.GetEncoding("gb2312"));
string stringReader = sr.ReadToEnd(); //流转字符串
sr.BaseStream.Seek(, SeekOrigin.Begin); //重置流 sr.Close();sr.Dispose(); //读取完后,关闭流
MemoryStream ms = new MemoryStream(System.Text.Encoding.Default.GetBytes(stringReader));
return ms;
// (1)byte[] bt=ms.ToArray();
//(2)MemoryStream ms=new MemoryStream();ms.Write(bt,0,ms.Length);
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace WindowsForm_CheckApk
{ public partial class Form1 : Form
{ public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
Cmd c = new Cmd(); string.Format("{0} d badging {1}", "aapt.exe的path", "apk的path"); var str = c.RunCmd(@"E:\迅雷下载\小米5线刷\ext4_unpacker\ext4_unpacker\aapt.exe d badging C:\14.apk"); //byte[] UTF8byte = Encoding.Convert(Encoding.Unicode, Encoding.UTF8, byteArray); List<Encoding> encodings = new List<Encoding>();
encodings.Add(System.Text.Encoding.Unicode);
encodings.Add(System.Text.Encoding.ASCII);
encodings.Add(System.Text.Encoding.Default);
encodings.Add(System.Text.Encoding.GetEncoding("GB2312")); //||GetEncoding("gbk") 都是GB2132
encodings.Add(System.Text.Encoding.GetEncoding("big5")); //繁体中文
encodings.Add(System.Text.Encoding.UTF7);
encodings.Add(System.Text.Encoding.UTF8);
encodings.Add(System.Text.Encoding.GetEncoding("GB18030")); List<byte[]> bytes = new List<byte[]>();
for (int i = ; i < encodings.Count; i++)
{
bytes.Add(encodings[i].GetBytes(str)); //以指定编码读取字符串到数组
} //Unicode 转 UTF8
byte[] UTF8byte = Encoding.Convert(Encoding.Unicode, Encoding.UTF8, bytes[]);
//将UTF8编码byte[]变为UTF8编码的字符串,编码一致,肯定可正确显示
string str1 = Encoding.UTF8.GetString(UTF8byte); List<string> outstrs = new List<string>(); //输出的字符串 for (int i = ; i < bytes.Count; i++)
{
outstrs.Add(Encoding.UTF8.GetString(bytes[i], , bytes[i].Length)); //
} //使用GetString方法,得到的string都是unicode编码的
var gb = System.Text.Encoding.Default.GetBytes(str); //使用ASCII读取和Unicode读取,都乱码 , 使用UTF8读取也乱码,,使用ANSI读取,使用UTF8解码
var gb2132_str = System.Text.Encoding.GetEncoding("GB2312").GetString(gb);
var utf8_str = System.Text.Encoding.UTF8.GetString(gb);
var ascii_str = System.Text.Encoding.ASCII.GetString(gb);
var default_str = System.Text.Encoding.Default.GetString(gb);
var ansi_str = System.Text.Encoding.UTF7.GetString(gb); var td = ""; //byte[] byteArray = System.Text.Encoding.Default.GetBytes("00"); //以默认编码读取字符串到 字节数组
//string aaa2 = System.Text.Encoding.Default.GetString(byteArray); //以默认编码 获得字节数组, 到字符串 }
/// <summary>
/// 字符串转为UniCode码字符串
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static string StringToUnicode(string s)
{
char[] charbuffers = s.ToCharArray();
byte[] buffer;
StringBuilder sb = new StringBuilder();
for (int i = ; i < charbuffers.Length; i++)
{
buffer = System.Text.Encoding.Unicode.GetBytes(charbuffers[i].ToString());
sb.Append(String.Format("\\u{0:X2}{1:X2}", buffer[], buffer[]));
}
return sb.ToString();
} /// 字符串转Unicode
/// </summary>
/// <param name="source">源字符串</param>
/// <returns>Unicode编码后的字符串</returns>
public static string String2Unicode(string source)
{
var bytes = Encoding.Unicode.GetBytes(source);
var stringBuilder = new StringBuilder();
for (var i = ; i < bytes.Length; i += )
{
stringBuilder.AppendFormat("\\u{0:x2}{1:x2}", bytes[i + ], bytes[i]);
}
return stringBuilder.ToString();
} //编码测试
private void button2_Click(object sender, EventArgs e)
{
string u16s = "忘記了啊abc"; //默认的字符编码是unicode,也就是utf16 //4种编码
Encoding utf8 = Encoding.UTF8;
Encoding utf16 = Encoding.Unicode;
Encoding gb = Encoding.GetEncoding("gbk");
Encoding b5 = Encoding.GetEncoding("big5"); //转换得到4种编码的字节流
byte[] u16bytes = utf16.GetBytes(u16s);
byte[] u8bytes = Encoding.Convert(utf16, utf8, u16bytes);
byte[] gbytes = Encoding.Convert(utf16, gb, u16bytes);
byte[] bbytes = Encoding.Convert(utf16, b5, u16bytes); // unicode
List<string> unicode_list = new List<string>();
unicode_list.Add("unicode: ");
foreach (byte c in u16bytes)
{
unicode_list.Add(((int)c).ToString("x") + " ");
} // UTF-8
List<string> utf8_list = new List<string>();
utf8_list.Add("utf8: ");
foreach (byte c in u8bytes)
{
utf8_list.Add(((int)c).ToString("x") + " ");
} // GBK
List<string> gbk_list = new List<string>();
gbk_list.Add("gbk: ");
foreach (byte c in gbytes)
{
gbk_list.Add(((int)c).ToString("x") + " ");
} // big5
List<string> big5_list = new List<string>();
big5_list.Add("big5: ");
foreach (byte c in bbytes)
{
big5_list.Add(((int)c).ToString("x") + " ");
} //得到4种编码的string
string u8s = utf8.GetString(u8bytes);
string gs = gb.GetString(gbytes);
string bs = b5.GetString(bbytes); Console.WriteLine("unicode: " + u16s + " " + u16s.Length.ToString());
Console.WriteLine("utf8: " + u8s + " " + u16s.Length.ToString());
Console.WriteLine("gbk: " + gs + " " + gs.Length.ToString());
Console.WriteLine("big5: " + bs + " " + bs.Length.ToString()); Console.Write("unicode: ");
foreach (char c in u16s)
{
Console.Write(((int)c).ToString("x") + " ");
}
Console.WriteLine(); Console.Write("utf8: ");
foreach (char c in u8s)
{
Console.Write(((int)c).ToString("x") + " ");
}
Console.WriteLine(); Console.Write("gb2312: ");
foreach (char c in gs)
{
Console.Write(((int)c).ToString("x") + " ");
}
Console.WriteLine(); Console.Write("big5: ");
foreach (char c in bs)
{
Console.Write(((int)c).ToString("x") + " ");
}
Console.WriteLine(); }
}
/// <summary>
/// Cmd 的摘要说明。
/// </summary>
public class Cmd: Process
{
private Process proc = null;
/// <summary>
/// 构造方法
/// </summary>
public Cmd()
{
proc = new Process();
} /// <summary>
/// 执行CMD语句
/// </summary>
/// <param name="cmd">要执行的CMD命令</param>
public string RunCmd(string cmd)
{
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();
proc.StandardInput.WriteLine(cmd);
proc.StandardInput.WriteLine("exit");
#region --测试代码 //System.IO.Stream t = proc.StandardOutput.BaseStream;
//byte[] bytes = new byte[t.Length]; //报错 流不支持查找
//t.Read(bytes, 0, bytes.Length);
//var out_str = System.Text.Encoding.UTF8.GetString(bytes);
//// (1)byte[] bt=ms.ToArray();
////(2)MemoryStream ms=new MemoryStream();ms.Write(bt,0,ms.Length); System.IO.StreamReader sOut = proc.StandardOutput;//这里是获取到一个StreamReader 流 byte[] bytes;
using (MemoryStream memstream = new MemoryStream())
{
int bytesRead = ;
byte[] buffer = new byte[];
while ((bytesRead = sOut.BaseStream.Read(buffer, , buffer.Length)) > )
{
memstream.Write(buffer, , bytesRead);
}
bytes = memstream.ToArray(); //FileStream keyfs = new FileStream(Server.MapPath("/key/regkey2.dat"), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Write);
//BinaryWriter w = null;
//w = new BinaryWriter(keyfs);
//for (int t = 0; t < bytes.Length; t++)
//{
// w.Write((byte)bytes[t]);
//} memstream.Close();
//w.Close();
//keyfs.Close(); } // t..CopyTo(ms);
//var ms = StreamToMemoryStream(t); var out_str = System.Text.Encoding.Default.GetString(bytes); #endregion #region --原始代码
string outStr = proc.StandardOutput.ReadToEnd(); proc.Close();
return outStr;
#endregion
}
System.IO.MemoryStream StreamToMemoryStream(System.IO.Stream instream)
{
System.IO.MemoryStream outstream = new System.IO.MemoryStream();
const int bufferLen = ;
byte[] buffer = new byte[bufferLen];
int count = ;
while ((count = instream.Read(buffer, , bufferLen)) > )
{
outstream.Write(buffer, , count);
}
return outstream;
}
/// <summary>
/// 打开软件并执行命令
/// </summary>
/// <param name="programName">软件路径加名称(.exe文件)</param>
/// <param name="cmd">要执行的命令</param>
public void RunProgram(string programName, string cmd)
{
Process proc = new Process();
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.FileName = programName;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();
if (cmd.Length != )
{
proc.StandardInput.WriteLine(cmd);
}
proc.Close();
}
/// <summary>
/// 打开软件
/// </summary>
/// <param name="programName">软件路径加名称(.exe文件)</param>
public void RunProgram(string programName)
{
this.RunProgram(programName, "");
}
}
先把流转换为字节数组
System.IO.StreamReader sOut = proc.StandardOutput;//这里是获取到一个StreamReader流
using (MemoryStream memstream = new MemoryStream())
{
int bytesRead = ;
byte[] buffer = new byte[];
while ((bytesRead = sOut.BaseStream.Read(buffer, , buffer.Length)) > )
{
memstream.Write(buffer, , bytesRead);
}
bytes = memstream.ToArray();
memstream.Close();
}
再把字节数组以指定编码转为字符串
var out_str = System.Text.Encoding.UTF8.GetString(bytes);
MVC 返回404,返回图片,流到数组,apk信息的更多相关文章
- 【转载】C#.NET WebApi返回各种类型(图片/json数据/字符串),.net图片转二进制流或byte
C#.NET WebApi返回各种类型(图片/json数据/字符串),.net图片转二进制流或byte 转载:http://www.itdos.com/Mvc/20150302/0741255.htm ...
- ASP.NET误人子弟教程:在MVC下如何返回图片
这几天忙着一些小事,也没有写什么了,今天,我们来玩一个比较简单的东东.就是在MVC下如何返回图片,相信,在传统WebForm下,大家都晓得怎么弄,方也不限于一种,但是,在架构较为严格的MVC里面,刚开 ...
- vue中图片返回404时,显示默认的图片
图片返回404时候的处理 <img :src="userMsg.portrait" ref="img" alt=""> _thi ...
- ASP.NET MVC请求特殊静态文件返回404 Not Found
今天在请求静态的json档案以及woff2档案,会返回404错误,需要在Web.Config里修改: <system.webServer> <modules> <remo ...
- mvc项目 ajax post 返回404错误
后台代码没有问题,但是一直出现404错误 原因:iis设置,请求中文件大小超过限制会被过滤掉,直接返回404. 解决:设置iis,应用程序->请求筛选->规则->编辑功能设置-> ...
- ASP.NET MVC – 关于Action返回结果类型的事儿(上)
原文:ASP.NET MVC – 关于Action返回结果类型的事儿(上) 本文转自:博客园-文超的技术博客 一. ASP.NET MVC 1.0 Result 几何? Action的 ...
- .Net之使用Jquery Ajax通过FormData对象异步提交图片文件到服务端保存并返回保存的图片路径
前言: 首先对于图片上传而言,在我们的项目开发中可以说出现的频率是相当的高的.这篇文章中,我将要描述的是在我们.Net中如何使用Jquery Ajax通过FormData对象异步提交图片文件到后台保存 ...
- mvc使用JsonResult返回Json数据
mvc使用JsonResult返回Json数据 controller 中定义以下方法: public JsonResult UpdateSingle(int id, string actionNa ...
- springmvc 返回 404 解决
Idea Maven springmvc spring 项目搭建中/url 可以访问controller,并且能返回正确的ModelAndView,但是页面总是显示404 项目结构: web.xml ...
随机推荐
- [luoguP1993] 小 K 的农场(差分约束 + spfa 判断负环)
传送门 差分约束系统..找负环用spfa就行 ——代码 #include <cstdio> #include <cstring> #include <iostream&g ...
- Hibernate注解开发教程
目录 第一章 类级别注解 1-1 本章简介 一.Hibernate注解简介 二.JPA与Hibernate的关系 三.Hibernate注解的分类 1-2 准备工作 1-3 @Entity注解 1-4 ...
- Mac OSX:最简单的安装ant方法
安装ant最简单的方法就是通过brew.步骤如下:1. 安装brew(如果已经安装可以跳过这步).ruby -e "$(curl -fsSL https://raw.github.com/m ...
- BZOJ 1492 货币兑换 cdq分治或平衡树维护凸包
题意:链接 方法:cdq分治或平衡树维护凸包 解析: 这道题我拒绝写平衡树的题解,我仅仅想说splay不要写挂,insert边界条件不要忘.del点的时候不要脑抽d错.有想写平衡树的去看140142或 ...
- 查看scn headroom变化趋势的几种方法
查看scn headroom变化趋势的几种方法 scn headroom问题,本文不做解释. 本文为自己的总结,脚本来自于oracle sr技术project师. 转载请注明出处http://blog ...
- DBI(i80)/DPI(RGB)/DSI【转】
本文转载自:http://blog.csdn.net/liuxd3000/article/details/17437317 (1)DBI接口 A,也就是通常所讲的MCU借口,俗称80 system接口 ...
- ArraySegment
第一个构造函数 Initializes a new instance of the ArraySegment<T> structure that delimits all the elem ...
- DCloud-MUI:代码块
ylbtech-DCloud-MUI:代码块 1.返回顶部 1. 怎么用? html 此底色代表最小触发字符 此底色代表非必要完整触发字符 *需HBuilder7.1+,或者下载m ...
- Java 8 实战 P1 Fundamentals
目录 Chapter 1. Java 8: why should you care? Chapter 2. Passing code with behavior parameterization Ch ...
- GROUPPING和ROLLUP的基本知识
1.GROUPPING 是一个聚合函数,它产生一个附加的列,当用 CUBE 或 ROLLUP 运算符添加行时,附加的列输出值为1,当所添加的行不是由 CUBE 或 ROLLUP 产生时,附加列值为0. ...