Console.Out 属性和 XmlDocument.Save 方法 (String)
Console.Out 属性
默认情况下,此属性设置为标准输出流。 此属性可以设置为另一个流SetOut方法。
请注意,调用Console.Out.WriteLine方法是等效于调用相应WriteLine方法。
下面的示例使用Out属性显示包含到标准输出设备的应用程序的当前目录中的文件的名称的数组。 然后将标准输出设置为一个名为 Files.txt 文件,并列出了对文件的数组元素。 最后,它将输出设置写入标准输出流,也不会显示数组元素到标准输出设备。
using System;
using System.IO; public class Example
{
public static void Main()
{
// Get all files in the current directory.
string[] files = Directory.GetFiles(".");
Array.Sort(files); // Display the files to the current output source to the console.
Console.WriteLine("First display of filenames to the console:");
Array.ForEach(files, s => Console.Out.WriteLine(s));
Console.Out.WriteLine(); // Redirect output to a file named Files.txt and write file list.
StreamWriter sw = new StreamWriter(@".\Files.txt");
sw.AutoFlush = true;
Console.SetOut(sw);
Console.Out.WriteLine("Display filenames to a file:");
Array.ForEach(files, s => Console.Out.WriteLine(s));
Console.Out.WriteLine(); // Close previous output stream and redirect output to standard output.
Console.Out.Close();
sw = new StreamWriter(Console.OpenStandardOutput());
sw.AutoFlush = true;
Console.SetOut(sw); // Display the files to the current output source to the console.
Console.Out.WriteLine("Second display of filenames to the console:");
Array.ForEach(files, s => Console.Out.WriteLine(s)); Console.ReadKey();
}
}

XmlDocument.Save 方法 (String)
只有当 PreserveWhitespace 设置为 true 时,才在输出文件中保留空白。
当前 XmlDocument 对象的 XmlDeclaration 确定保存的文档的编码属性。编码属性值取自 XmlDeclaration.Encoding 属性。如果 XmlDocument 不具有 XmlDeclaration,或者如果 XmlDeclaration 没有编码属性,则保存的文档也不会有这些属性。
保存文档时,生成 xmlns 属性以正确保持节点标识(本地名称 + 命名空间 URI)。例如,下面的 C# 代码
XmlDocument doc = new XmlDocument();
doc.AppendChild(doc.CreateElement("item","urn:1"));
doc.Save(Console.Out);
生成此 xmls 属性 <item xmls="urn:1"/>。
该方法是文档对象模型 (DOM) 的 Microsoft 扩展。
using System;
using System.Xml; public class Sample { public static void Main() { // Create the XmlDocument.
XmlDocument doc = new XmlDocument();
doc.LoadXml("<item><name>wrench</name></item>"); // Add a price element.
XmlElement newElem = doc.CreateElement("price");
newElem.InnerText = "10.95";
doc.DocumentElement.AppendChild(newElem); // Save the document to a file. White space is
// preserved (no white space).
doc.PreserveWhitespace = true;
doc.Save("data.xml"); }
}
Console.Out 属性和 XmlDocument.Save 方法 (String)的更多相关文章
- spring cloud spring boot JPA 克隆对象修改属性后 无法正常的执行save方法进行保存或者更新
2019-12-1220:34:58 spring cloud spring boot JPA 克隆对象修改属性后 无法正常的执行save方法进行保存或者更新 未解决
- jQuery操纵DOM元素属性 attr()和removeAtrr()方法使用详解
jQuery操纵DOM元素属性 attr()和removeAtrr()方法使用详解 jQuery中操纵元素属性的方法: attr(): 读或者写匹配元素的属性值. removeAttr(): 从匹配的 ...
- 扩展JPA方法,重写save方法
为什么要重构save? jpa提供的save方法会将原有数据置为null,而大多数情况下我们只希望跟新自己传入的参数,所以便有了重写或者新增一个save方法. 本着解决这个问题,网上搜了很多解决方案, ...
- 华为交换机Console口属性配置
华为交换机Console口属性配置 一.设置通过账号和密码(AAA验证)登陆Console口 进入 Console 用户界面视图 <Huawei>system-view [Huawei]u ...
- 转载:java 中对类中的属性使用set/get方法的意义和用法
经常看到有朋友提到类似:对类中的属性使用set/get方法的作用?理论的回答当然是封闭性之类的,但是这样对我们有什么作用呢?为什么要这样设计?我直接使用属性名来访问不是更直接,代码更简洁明了吗?下面我 ...
- C# String.split()用法小结。String.Split 方法 (String[], StringSplitOptions)
split()首先是一个分隔符,它会把字符串按照split(' 字符')里的字符把字符串分割成数组,然后存给一个数组对象. 输出数组对象经常使用foreach或者for循环. 第一种方法 string ...
- JavaScript Number 对象 Javascript Array对象 Location 对象方法 String对象方法
JavaScript Number 对象 Number 对象属性 属性 描述 constructor 返回对创建此对象的 Number 函数的引用. MAX_VALUE 可表示的最大的数. MIN_V ...
- [原创]java WEB学习笔记79:Hibernate学习之路--- 四种对象的状态,session核心方法:save()方法,persist()方法,get() 和 load() 方法,update()方法,saveOrUpdate() 方法,merge() 方法,delete() 方法,evict(),hibernate 调用存储过程,hibernate 与 触发器协同工作
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...
- 01-03-02-2【Nhibernate (版本3.3.1.4000) 出入江湖】CRUP操作-Save方法的一些问题
此文由于当时不知道NHibernate的Sava方法不是更新操作,不知道Save就是Add,造成如下荒唐的求证过程,但结论是对的 ,可报废此文,特此声明. NHibernate--Save方法: Cu ...
随机推荐
- rev 反向输出文件内容
1.命令功能 rev 按行反向输出文件内容 2.语法格式 rev file 3.使用范例 [root@localhost ~]# echo {a..k} >> test [root@lo ...
- 计蒜客 蓝桥模拟 F. 结果填空:数独
代码: #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream& ...
- DbgPrint
windbg查看 IoCreateDevice IRP请求 i/o 中断 IRP_MN_START_DEVICE DeviceType == USB_DEVICE printk linux htt ...
- 【学习】019 SpringBoot
一.SpringBoot介绍 1.1.SpringBoot简介 在您第1次接触和学习Spring框架的时候,是否因为其繁杂的配置而退却了?在你第n次使用Spring框架的时候,是否觉得一堆反复黏贴的配 ...
- moc_XXXX.o:(.data.rel.ro._ZTI12CalculatorUI[_ZTI12CalculatorUI]+0x10): undefined reference to `typeinfo for QWidget' collect2: error: ld returned 1 exit status make: *** [Makefile:144: myCalculator]
main.cpp:(.text.startup+0x22): undefined reference to `QApplication::QApplication(int&, char**, ...
- CentOS8 安装部署Apache+Php+MariaDB(pdo扩展)
使用新的CentOS8系统架设PHP服务器,因现在主流数据库mysql已闭源了,所以现在改为使用MariaDB.而php7以后不支持mysqli链接,只有pdo方式,为了安装pdo扩展,所以重新编译安 ...
- LeetCode--078--子集(python)
给定一组不含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集). 说明:解集不能包含重复的子集. 示例: 输入: nums = [1,2,3]输出:[ [3], [1], [2], ...
- 微信小程序-坑1-await-async
VM45:1 thirdScriptError sdk uncaught third Error regeneratorRuntime is not defined ReferenceError: r ...
- iOS 指定位置切圆角不生效问题
如果是在VC中操作,需要在viewDidLayoutSubviews方法里 - (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; ...
- SQL Server性能调优--优化建议(二)
序言 优化建议 库表的合理设计对项目后期的响应时间和吞吐量起到至关重要的地位,它直接影响到了业务所需处理的sql语句的复杂程度,为提高数据库的性能,更多的把逻辑主外键.级联删除.减少check约束.给 ...