关于File.ReadAllText Method (String)
来源:互联网 发布:访问网站出现 php探针 编辑:程序博客网 时间:2024/06/07 14:56
File.ReadAllText Method (String)
用在读取电量了,但是发现他没有关闭流,查了一下
https://msdn.microsoft.com/en-us/library/ms143368(v=vs.110).aspx
Remarks
This method opens a file, reads each line of the file, and then adds each line as an element of a string. It then closes the file. A line is defined as a sequence of characters followed by a carriage return ('\r'), a line feed ('\n'), or a carriage return immediately followed by a line feed. The resulting string does not contain the terminating carriage return and/or line feed.
读取全部行的信息,之后就自己关闭了,mark一下
using System;using System.IO;using System.Text;class Test{ public static void Main() { string path = @"c:\temp\MyTest.txt"; // This text is added only once to the file. if (!File.Exists(path)) { // Create a file to write to. string createText = "Hello and Welcome" + Environment.NewLine; File.WriteAllText(path, createText); } // This text is always added, making the file longer over time // if it is not deleted. string appendText = "This is extra text" + Environment.NewLine; File.AppendAllText(path, appendText); // Open the file to read from. string readText = File.ReadAllText(path); Console.WriteLine(readText); }}
by wolf96 2017/7/13
阅读全文
0 0
- 关于File.ReadAllText Method (String)
- C# File.ReadAllText()
- C#控制台基础 file.readalltext把小容量的txt中的内容放到一个string里
- 【C#】利用System.IO中的File类中的ReadAllText与WriteAllText输入输出小文件
- foreach (FileInfo NextFile in fileInfo) //遍历文件 System.IO.File.ReadAllText(FilePath);
- String..::.Compare Method (String, String)
- File native method
- Python, file readline() method
- DateTime.ToString Method (String)
- Python String translate() Method
- Extend Method: String.AppendRight
- Python String find() Method
- Python String Method
- JavaScript String split() Method
- Java - String length() Method
- 关于 java.io 中的 File.listFiles(String dir)
- 15、关于String,File,InputStream之间的相互转换
- C#控制台基础 file.readalltext使用相对路径与绝对路径去读取 与exe在同一目录下的txt文件
- HDU 1394:Minimum Inversion Number
- IT之路-进制、运算符、控制语句-ZCSDN.2017.7.13
- (52)多个生产者多个消费者出现的问题,解决方式synchronized方法和Lock方法
- JackSon将json串转成List<Object>,异常com.fasterxml.jackson.databind.JsonMappingException
- faceDetection对比实验
- 关于File.ReadAllText Method (String)
- Spring学习之AOP基础
- 使一个布局中的所有事件失效
- DC-4: 循环结构
- CSS基础知识一
- POJ 3159 Candies 笔记
- 离散傅里叶变换
- 51nod 1453 抽彩球 (思维+排列组合)
- Groovy的JavaBean