标签:
1.Using 打开什么,就自动关闭什么,其他的包含的连接不管
XML文档读取
重点:必须是标准的xml文档,否则会出错
string xmlxx = @"C:\1.xml";using (XmlReader reader = XmlReader.Create(xmlxx)){while (reader.Read()){if (reader.NodeType == XmlNodeType.Text){Console.WriteLine(reader.Value + "\r\n");}}}Console.ReadKey();
StreamReader sr = new StreamReader(@"E:\\111.txt", Encoding.GetEncoding("GB2312")); //通常需要转码为GB2312int Ichar = 0;while ((Ichar = sr.Read()) != -1) // 不再有可用的字符,则为 -1{Console.Write(Convert.ToChar(Ichar).ToString()); //StreamReader的Read方法返回的是字符串的二进制数字,可以用ToChar转换成ASCII字符串,将int类型转成ASCII字符}Console.ReadKey();
标签:
原文地址:http://www.cnblogs.com/weloveshare/p/5294816.html