将扫码枪扫描的二维码写入TXT文本文件,然后用RationalDMIS读入为变量后发现开头有乱码,查看编码格式默认是UTF-8,查询MSDN中相关信息发现 WriteAllText 默认是UTF-8格式,用 System.Text.Encoding.ASCII 参数设置为ASCII编码即可正常读入RationalDMIS;
将: My.Computer.FileSystem.WriteAllText("C:\RationalDMIS\Data\bar.txt", TextBox1.Text, False) 改为: My.Computer.FileSystem.WriteAllText("C:\RationalDMIS\Data\bar.txt", TextBox1.Text, False, System.Text.Encoding.ASCII)