如何通过批处理以UTF-8格式创建文本文件。 [英] How a text file can be created in UTF-8 format through batch processes.

查看:731
本文介绍了如何通过批处理以UTF-8格式创建文本文件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我遇到了批处理创建的文本文件问题。实际上,批处理过程以ASCII格式创建文件,但这些文本文件充当其他系统(SSIS包)的输入,因此有时下游系统无法理解文件的内容。那么我可以在我的批处理文件中制作任何方法或蓝绿色,以便以UTF-8格式而不是ASCII格式保存文本文件。



谢谢和问候

Dheeraj Jindal

Hi All,
I am facing a problem of text files that are been created by a batch process. Actually the batch process creates the file in ASCII format but these text files act as a input to some other system(SSIS Package), so sometimes the contents of the files are not understood by the downstream system. So is there any way or teal which I can make in my batch file so that it saves the text file in UTF-8 format rather than ASCII.

Thanks & Regards
Dheeraj Jindal

推荐答案

Dheeraj -



你可以使用编码来保证您的文件保存为UT8。
Dheeraj -

You can use Encoding to guarantee your file is saved as UT8.
// depending on how long your file is, you may need to take a different approach 
// how the text is read and written to the file
string text = File.ReadAllText(path);
byte[] buffer = UTF8Encoding.UTF8.GetBytes(text); 
                
using (FileStream fs = File.OpenWrite(utf8Path))
{
    fs.Write(buffer, 0, buffer.Length);
}


这篇关于如何通过批处理以UTF-8格式创建文本文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆