File.WriteAllText 在每个字母和引号后插入一个空格。

例子:

原始文件

"JobID" "ParentJobID"

新文件
" J o b I D "    " P a r e n t J o b I D "

代码
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProcessOutputLogTransfer
{
    class Program
    {
        static void Main(string[] args)
        {

            string content = File.ReadAllText(@"C:\Documents and Settings\All Users\Application Data\Microsoft\Windows NT\MSFax\ActivityLog\OutboxLOG.txt");

        File.WriteAllText(@"C:\FAXLOG\OutboxLOG.txt", content, Encoding.UTF8);
        }
    }
}

最佳答案

我不认为是 WriteAllText 在做这件事。我相信它是 ReadAllText ,它默认使用 UTF-8 读取——我怀疑你的 OutboxLOG.txt 文件实际上是用 UTF-16 编写的。试试这个:

string inputPath = @"C:\Documents and Settings\All Users\Application Data\"
                 + @"Microsoft\Windows NT\MSFax\ActivityLog\OutboxLOG.txt";
string outputPath = @"C:\FAXLOG\OutboxLOG.txt";

string content = File.ReadAllText(inputPath, Encoding.Unicode);
File.WriteAllText(outputPath, content, Encoding.UTF8);

关于c# - File.WriteAllText 在每个字符后插入一个空格,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8591700/

10-14 15:42
查看更多