asp.net怎么解决文本中文乱码的问题
发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,本篇内容介绍了"asp.net怎么解决文本中文乱码的问题"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成
千家信息网最后更新 2026年11月01日asp.net怎么解决文本中文乱码的问题
本篇内容介绍了"asp.net怎么解决文本中文乱码的问题"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
////// 解决文本中文乱码 各类文本编码转UTF-8 文本 /// /// 原路径 /// 临时保存路径 /// 新的文件路径 ///新文件路径 public static string GetUtf8(string fullPath,string savePath,string strnew) { Encoding e =GetFileEncodeType(fullPath); System.IO.File.Create(savePath).Close(); using (StreamReader sr = new StreamReader(fullPath, e, false)) { string utf8info = string.Empty; Encoding utf8 = Encoding.UTF8; // Convert the string into a byte[]. byte[] unicodeBytes = e.GetBytes(sr.ReadToEnd()); // Perform. the conversion from one encoding to the other. byte[] asciiBytes = Encoding.Convert(e, utf8, unicodeBytes); // Convert the new byte[] into a char[] and then into a string. // This is a slightly different approach to converting tillustrate // the use of GetCharCount/GetChars. char[] asciiChars = new char[utf8.GetCharCount(asciiBytes, 0, asciiBytes.Length)]; utf8.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0); utf8info = new string(asciiChars); using (StreamWriter sw = new StreamWriter(savePath, false, Encoding.UTF8)) { sw.Write(utf8info); } } System.IO.File.Delete(fullPath); System.IO.File.Copy(savePath,strnew,true); System.IO.File.Delete(savePath); return strnew; }方法2 using (FileStream fs = new FileStream(fullPath, FileMode.Open)) { using (StreamReader sr = new StreamReader(fs,Encoding.Default)) { while (!sr.EndOfStream) { string sLine = sr.ReadLine(); //StringBuilder b = new StringBuilder(); //b.AppendLine(sLine); //另存到其他txt文件中 using (StreamWritersw=System.IO.File.AppendText(savepath)) { //string n = b.ToString(); sw.WriteLine(sLine.ToString()); } } } } System.IO.File.Delete(fullPath); string strNewFile = fullPath; System.IO.File.Copy(savepath, strNewFile, true); System.IO.File.Delete(savepath); //using (StreamReader sr = new StreamReader(strNewFile,Encoding.Default, false)) //{ // using (StreamWriter sw = new StreamWriter(fullPath, falsEncoding.UTF8)) // { // sw.Write(Server.HtmlEncode(sr.ReadToEnd())); // } //} //System.IO.File.Delete(strNewFile); FileInfo fileNew = new FileInfo(strNewFile); sourcesFile.File_Size = fileNew.Length; this.sourcesFileService.Save(sourcesFile); }
"asp.net怎么解决文本中文乱码的问题"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!
文本
路径
乱码
中文
文件
问题
内容
更多
知识
实用
学有所成
接下来
困境
实际
情况
文章
方法
案例
编带
编码
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
喔噻互联网科技有限公司
互联网科技英文
万易互联网科技有限公司
深圳天众互联网科技公司
广西互联网科技公司
郑州华宇互联网科技
亿人帮互联网科技
科技互联网创业计划书
佩信高科技互联网
受益于互联网科技的高速发展
银川新华互联网科技学校联系电话
2021互联网科技公司排名
北京市互联网新科技
富国互联网金融科技混合基金
下一代互联网重大应用科技园
广州互联网高科技取餐柜
信承诺互联网科技有限公司
科技和互联网行业的特点
深圳互联网科技园地址
保山浩联互联网科技有限公司
咖啡
互联网科技有限公司经营范围
互联网金融公司科技
唐信互联网科技 大连
蓝色互联网科技
科技互联网的估值
贵州叶脉互联网科技有限公司所属行业
青岛科技大学互联网大赛研究生
互联网保险科技创业
恒生互联网科技业指数调整周期