有关Wscript.exe *.vbs 的中文字编码( utf-8)问题

(一) WSH script程式,utf-8的档案A 中文字抄至B时会变乱码。
inputFilePath = "D:\test\A.txt"
outputFilePath = "D:\test\B.txt"

Set fso = CreateObject("Scripting.FileSystemObject")
Set inFid = fso.OpenTextFile(inputFilePath ,1 ,-1)
Set outFid = fso.OpenTextFile(outputFilePath ,8 , -1)
do until inFid.atEndOfStream
myLine = inFid.ReadLine
outFid.WriteLine myLine
loop
inFid.Close
outFid.Close

(二) Powershell script 程式,utf-8档案B中 加入中文字型也是异常。
1. my.ps1 的程式如下:
Add-Content D:\test\B.txt "中文字" -Encoding utf8
执行 .ps1后,档案B中出现乱码!
2.直接在 powershell console下直行此单行指令,却又是正常。


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章