偶用的是文本文件作数据源,读出数据进行处理后,再把数据集写到一个新的文本文件里,现在用的是StreamWriter一条一条来写。难道就没有更有效率的方法了吗?

解决方案 »

  1.   

    private void WriteXmlToFile(DataSet thisDataSet) {
        if (thisDataSet == null) { return; }
        // Create a file name to write to.
        string filename = "myXmlDoc.xml";
        // Create the FileStream to write with.
        System.IO.FileStream myFileStream = new System.IO.FileStream
           (filename, System.IO.FileMode.Create);
        // Create an XmlTextWriter with the fileStream.
        System.Xml.XmlTextWriter myXmlWriter = 
           new System.Xml.XmlTextWriter(myFileStream, System.Text.Encoding.Unicode);
        // Write to the file with the WriteXml method.
        thisDataSet.WriteXml(myXmlWriter);   
        myXmlWriter.Close();
    }.NET中将数据写如文本类型文件的首选就是XML了。