我有一个UTF-7格式的文本文件,我想用同样的数据创建另一个文件,如下所示:
using (var sw = new StreamWriter(@"D:\toto.csv.copy", false, Encoding.UTF7))
{
using (var sr = new StreamReader(@"D:\toto.csv", Encoding.UTF7))
{
string line;
while (null != (line = sr.ReadLine()))
{
sw.WriteLine(line);
}
}
}在原始文件中,第一行是:?TEST?在复制文件中,第一行是:+AKQ-TEST+AKQ-
原始文件是UTF-7格式的,当我在调试模式下查看行变量时,我可以在行变量中看到“TEST?”。
你能帮帮我吗?
非常感谢
发布于 2010-10-21 23:55:32
尝试在编写器上使用自定义编码,以允许在输出中使用可选字符。
UTF7Encoding allowOptionals = new UTF7Encoding(true);
using (var sw = new StreamWriter(@"D:\toto.csv.copy", false, allowOptionals))
{
using (var sr = new StreamReader(@"D:\toto.csv", Encoding.UTF7))
{
string line;
while (null != (line = sr.ReadLine()))
{
sw.WriteLine(line);
}
}
} https://stackoverflow.com/questions/3984220
复制相似问题