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 ...
随机推荐
- fpga ip
原文地址:altera FIR ip核 license破解作者:王永刚Aether 在证书文件中添加一段: FEATURE 6AF7_0012 alterad 2035.12 permanent un ...
- 一、.net core 集成vue
一.npm安装WebPack (这种情况就会出现在项目外部,只不过借用VS的程序包管理器控制台获取而已) 右击新建项目创建webpack
- NLP 中任务及相关概念
命名实体识别 命名实体识别(Named Entity Recognition,简称NER),又称作"专名识别",是指识别文本中具有特定意义的实体,主要包括人名.地名.机构名.专有名 ...
- adam优化
AdaGrad (Adaptive Gradient,自适应梯度) 对每个不同的参数调整不同的学习率, 对频繁变化的参数以更小的步长进行更新,而稀疏的参数以更大的步长进行更新. gt表示第t时间步的梯 ...
- jvm 堆
1.堆内存线程共享,在虚拟机启动时创建. 2.几乎所有的对象实例都在堆上分配:栈中存放基本数据类型和堆中对象的引用. GC回收 程序计数器.虚拟机栈.本地方法栈随线程而生,随线程而灭.栈中的栈帧随着方 ...
- bzoj4129 Haruna’s Breakfast 树上带修莫队+分块
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4129 题解 考虑没有修改的序列上的版本应该怎么做: 弱化的题目应该是这样的: 给定一个序列,每 ...
- 13 Spring Boot Shiro使用JS-CSS-IMG
filterChainMap.put("/403", "anon");filterChainMap.put("/assets/**", &q ...
- vue路由传参并跳转页面
在vue项目中参数的传递可以使用本地缓存或者Vuex,那么vue能不能像小程序一样路由传参呢,显然是可以的而且非常简单 方式一:query传参 //传参 go(){ that.$router.push ...
- leetcode打卡
leetcode刷题打卡 刷题链接 夸夸群 刷题记录链接 期中颜色不一样的,是刷题中遇到问题的,以后需要强化 [x] 6.1 打卡 [x] 6.2 打卡 中间因个人原因没做题,后面慢慢补上 [x] 6 ...
- angular项目开发
第 1 步:安装 Angular CLI 你可以使用 Angular CLI 来创建项目.生成应用和库代码,以及执行各种持续开发任务,比如测试.打包和部署. 全局安装 Angular CLI. 要使用 ...