首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

各位看看是怎么回事啊如何运行的时候出异常呢?

2012-01-22 
各位大虾看看是咋回事啊??怎么运行的时候出错误呢???usingSystemusingSystem.XmlnamespaceReadXml{class

各位大虾看看是咋回事啊??怎么运行的时候出错误呢???
using   System;
using   System.Xml;    

namespace   ReadXml
{
        class   Class1
        {
                static   void   Main(   string[]   args   )
                {
                        //   创建一个XmlTextReader类的对象并调用Read方法来读取文件
                        XmlTextReader   textReader     =   new   XmlTextReader( "C:\books.xml ");
                        textReader.Read();
                        //   节点非空则执行循环体
                        while   (   textReader.Read()   )
                        {
                                //   读取第一个元素
                                textReader.MoveToElement();
                                Console.WriteLine( "XmlTextReader   Properties   Test ");
                                Console.WriteLine( "=================== ");    

                                //   读取该元素的属性并显示在控制台中
                                Console.WriteLine( "Name: "   +   textReader.Name);
                                Console.WriteLine( "Base   URI: "   +   textReader.BaseURI);
                                Console.WriteLine( "Local   Name: "   +   textReader.LocalName);
                                Console.WriteLine( "Attribute   Count: "   +   textReader.AttributeCount.ToString());
                                Console.WriteLine( "Depth: "   +   textReader.Depth.ToString());
                                Console.WriteLine( "Line   Number: "   +   textReader.LineNumber.ToString());
                                Console.WriteLine( "Node   Type: "   +   textReader.NodeType.ToString());
                                Console.WriteLine( "Attribute   Count: "   +   textReader.Value.ToString());
                        }


                }
        }
}
从网上找的一个读xml文档的程序。在c盘下建立了一个books.xml文档。结果。。
它提示出现System.IO.Exception   错误,文件名,目录名或者卷名出现错误。
怎么回事啊   。。

[解决办法]
new XmlTextReader( "C:\\books.xml ");
或者
new XmlTextReader(@ "C:\books.xml ");

[解决办法]
楼上的正确...

XmlTextReader textReader = new XmlTextReader( "C:\books.xml ");

路径错了.

热点排行