StreamWriter postscript文件以编码问题结束

时间:2014-01-31 11:27:08

标签: c# encoding streamwriter postscript

下面是我正在编写的用于对postscript文件进行一些处理的代码。

    private static void ProcessPostScriptFile(string inFileName, string outFileName)
    {
        var inputFile = new System.IO.StreamReader(inFileName, Encoding.UTF8);
        var outputFile = new System.IO.StreamWriter(outFileName, false, Encoding.UTF8);

        string line;
        while ((line = inputFile.ReadLine()) != null)
        {
            //Do some processing, just to demo that the issue is not related to my processing 
            outputFile.WriteLine(line);
        }
        inputFile.Close();
        outputFile.Close();
    }

输入ps文件包含版权符号的一些字符: enter image description here

但是,输出文件显示的行如下:
 版权所有 1991,2002Adobe Systems Incorporated。

任何人都可以指导我如何解决这个问题。

谢谢!

2 个答案:

答案 0 :(得分:0)

您可以尝试使用streamreader构造函数whit参数detectEncodingFromByteOrderMarks http://msdn.microsoft.com/en-us/library/7bc2hwcb%28v=vs.110%29.aspx然后使用参数CurrentEncoding创建streamwriter

答案 1 :(得分:0)

我不得不改变

var inputFile = new System.IO.StreamReader(inFileName, Encoding.UTF8);
var outputFile = new System.IO.StreamWriter(outFileName, false, Encoding.UTF8);

var inputFile = new System.IO.StreamReader(inFileName, Encoding.GetEncoding(1252)); 
var outputFile = new System.IO.StreamWriter(outFileName, false, Encoding.GetEncoding(1252));