C#循环读取文件流,按行读取
public Dictionary<string,string> GetSourceDisksElements(String section)
{
section = "[" + section;
Dictionary<string, string> keyToValue = new Dictionary<string, string>();
//打开文件流,开始读取文件
using (StreamReader sin = new StreamReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)))
{
for (String str = sin.ReadLine(); str != null; str = sin.ReadLine())
{
if (str.Trim().StartsWith(section, StringComparison.OrdinalIgnoreCase)) //some section has comment.
{
for (str = sin.ReadLine(); str != null && !str.Trim().StartsWith("["); str = sin.ReadLine()) //loop for get string, until to next section or end of file.
{
if (!String.IsNullOrEmpty(str.Trim()) && !str.Trim().StartsWith(";")) //drop the comment line and empty line. //去掉name-value对的限制,因为存在无=的情况。20100309.str.Contains('=') && only get the name-value pair line.
{
String[] keyValues = str.Split('=');
if (section.Equals("[SourceDisksNames"))
{
string[] noCommentValues = keyValues[].Split(';');
string realValue = noCommentValues[].Trim(); String[] sourceDiskCfg = realValue.Split(','); //disk-description[,[tag-or-cab-file],[unused],[path],[flags][,tag-file]] (tag-file : Windows XP and later versions of Windows)
String diskpath = String.Empty;
if (sourceDiskCfg.Length > )
diskpath = sourceDiskCfg[].Trim(); if (diskpath.StartsWith("\""))
diskpath = RemoveQuotes(diskpath); if (!String.IsNullOrEmpty(diskpath) && diskpath.StartsWith("."))
diskpath = diskpath.Substring(diskpath.IndexOf('\\')); //
if (!String.IsNullOrEmpty(diskpath) && !diskpath.StartsWith("\\"))
diskpath = "\\" + diskpath; keyToValue.Add(keyValues[].Trim(), diskpath);
}
else
{ string[] noCommentValues = keyValues[].Split(';');
string realValue = noCommentValues[].Trim();
keyToValue.Add(keyValues[].Trim(), realValue);
}
}
}
break;
}
}
}
return keyToValue;
}
C#循环读取文件流,按行读取的更多相关文章
- 文件_ _android从资源文件中读取文件流并显示的方法
======== 1 android从资源文件中读取文件流并显示的方法. 在android中,假如有的文本文件,比如TXT放在raw下,要直接读取出来,放到屏幕中显示,可以这样: private ...
- Java利用内存映射文件实现按行读取文件
我们知道内存映射文件读取是各种读取方式中速度最快的,但是内存映射文件读取的API里没有提供按行读取的方法,需要自己实现.下面就是我利用内存映射文件实现按行读取文件的方法,如有错误之处请指出,或者有更好 ...
- [转]从minio中读取文件流进行下载文件
本文转自:https://blog.csdn.net/ZHANGLIZENG/article/details/82892678 一.获取Minio连接 public static String ...
- Linux:读取文件,每行拆分,并比较拆分数组长度
读取文件,每行拆分,并比较拆分数组长度 #!/bin/bash FILENAME=./.txt function While_read_LINE(){ cat $FILENAME | while re ...
- python之从文件中按行读取数据
#!/usr/bin/env python3 # -*- coding: utf-8 -*- __author__ = 'jiangwenwen' # 从文件中按行读取数据 file = open(& ...
- c++ 读取文件 最后一行读取了两次
用ifstream的eof(),竟然读到文件最后了,判断eof还为false.网上查找资料后,终于解决这个问题. 参照文件:http://tuhao.blogbus.com/logs/21306687 ...
- java 读取文件流
搬运自速学堂:https://www.sxt.cn/Java_jQuery_in_action/ten-iqtechnology.html JAVA中IO流体系: 四大IO抽象类 ·InputStre ...
- C++基于文件流和armadillo读取mnist
发现网上大把都是用python读取mnist的,用C++大都是用opencv读取的,但我不怎么用opencv,因此自己摸索了个使用文件流读取mnist的方法,armadillo仅作为储存矩阵的一种方式 ...
- Java读取文件时第一行出现乱码“?”问号
我们在使用Java在读取文件(txt.dat等)时,如果文件不是utf-8格式的话,读取结果会出现,中文字符变乱码的情况,所以一般在读取时转为UTF-8格式读取. 但这时会出现一种情况,第一次读取第一 ...
随机推荐
- 为Quartus工程生成rbf文件的方法
rbf文件是Quartus编译生成的fpga配置文件的二进制数据量格式的文件,主要用于使用外部主机通过PS方式配置FPGA. 在含ARM硬核的SoC FPGA中,可以使用HPS配置FPGA,配置时分为 ...
- [翻译] FastReport "Text" 对象中使用表达式
文本对象的最重要的功能之一是它不仅能够显示静态文本还能显示表达式.表达式混合在正常的文本内容中,让我们看一个简单的例子,他是如何工作的.在文件对象的内容中,输入以下字符: Hello, World! ...
- Regex Golf练习笔记(1)
正则表达式进阶练习:https://alf.nu/RegexGolf (此练习笔记) 正则表达式验证:https://regexr.com/ (1) (2) 注释:每个词的三个字母在后面重复出现了一 ...
- Redis连接异常
1. 以指定配置文件启动Redis,否则配置的东西不生效 redis-cli shutdown 关闭 $ redis-server ./redis.conf 2.连接异常 redis.conf 配置文 ...
- Office - Outlook
将邮件存到本地 服务器容量有限,避免丢失和经常提示容量不足 步骤 在File->Account Settings->Account Settings下面 在Data Files标签页新建一 ...
- flume在windows环境下的使用
Flume是Cloudera提供的一个高可用的,高可靠的,分布式的海量日志采集.聚合和传输的系统,Flume支持在日志系统中定制各类数据发送方,用于收集数据:同时,Flume提供对数据进行简单处理, ...
- Day 19 re 模块 random模块,正则表达式
https://www.cnblogs.com/Eva-J/p/7228075.html#_label10 findall search match方法 和 search相比 match自带 ^ se ...
- python学习笔记6-集合
# 集合是无序且不可重复的元素的集合 a = set([1,3,1,3,3,2,2,5]) a # {1, 2, 3, 5} b = set(range(2,5)) b # {2, 3, 4} # 1 ...
- css3效果隔两秒旋转然后停两秒再继续旋转,无限循环
1.旋转效果 <style type="text/css"> /*底部天象APP红包下载*/ .public_footer_app,.animation{ positi ...
- 去除eclipse的validating
删除.project文件中的validator,如 <buildCommand> <name>org.eclipse.wst.jsdt.core.javascriptValid ...