我正在尝试将一些信息写入文本文件,但第二行在行之间留有空格
编码 :
private void CreateDriversList()
{
StreamWriter w = new StreamWriter(contentDirectory + "\\" + "Drivers.txt");
w.WriteLine("Module Name Display Name Driver Type Link Date");
w.WriteLine("============ ====================== ============= ======================");
//Declare, Search, and Get the Properties in Win32_SystemDriver
System.Management.SelectQuery query = new System.Management.SelectQuery("Win32_SystemDriver");
System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(query);
foreach (System.Management.ManagementObject ManageObject in searcher.Get())
{
w.WriteLine(ManageObject["Name"].ToString());
w.WriteLine(" " + ManageObject["DisplayName"].ToString());
}
w.Close();
}
一旦我添加了这一行:
w.WriteLine(" " + ManageObject["DisplayName"].ToString());
文本文件中的结果是这样的:
Module Name Display Name Driver Type Link Date
============ ====================== ============= ======================
1394ohci
1394 OHCI Compliant Host Controller
3ware
3ware
ACPI
Microsoft ACPI Driver
acpiex
Microsoft ACPIEx Driver
acpipagr
在我添加该行之前,文本文件是这样的:
Module Name Display Name Driver Type Link Date
============ ====================== ============= ======================
1394ohci
3ware
ACPI
acpiex
acpipagr
AcpiPmi
我现在只想添加显示名称行,所以我添加了空格,因此该行将在显示名称下开始,然后在行之间添加空格。
我该如何解决?
**
最后,文本文件应如下所示:
Module Name Display Name Driver Type Link Date
============ ====================== ============= ======================
1394ohci 1394 OHCI Compliant Ho Kernel 7/26/2012 5:26:46 AM
3ware 3ware Kernel 3/8/2012 10:33:45 PM
ACPI Microsoft ACPI Driver Kernel 9/20/2012 9:09:16 AM
acpiex Microsoft ACPIEx Drive Kernel 7/26/2012 5:25:57 AM
acpipagr ACPI Processor Aggrega Kernel 7/26/2012 5:27:16 AM
AcpiPmi ACPI Power Meter Drive Kernel 7/26/2012 5:27:33 AM
acpitime ACPI Wake Alarm Driver Kernel 7/26/2012 5:27:37 AM
并且在显示名称行中,也可能在模块名称行中,以确保名称将在一行全名中。
例如在显示名称中:1394 OHCI Compliant Ho 应该是:1394 OHCI Compliant Host Controller
**
Module Name Display Name Driver Type Link Date
============ ====================== ============= ======================
1394ohci 1394 OHCI Compliant Host Controller
3ware 3ware
ACPI Microsoft ACPI Driver
acpiex Microsoft ACPIEx Driver
acpipagr ACPI Processor Aggregator Driver
AcpiPmi ACPI Power Meter Driver