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格式读取. 但这时会出现一种情况,第一次读取第一 ...
随机推荐
- ViewGroup onInterceptTouchEvent,ViewGroup onTouchEvent,View onTouchEvent执行顺序说明
今天抽出了一些时间实践了viewgroup和view的触摸事件顺序,之前也试过,总是忘记,今天记下笔记说明一下 首先 onInterceptTouchEvent只会出现在viewgroup中,view ...
- ABP 基础设施层——集成 NHibernate
本文翻译自ABP的官方教程<NHibernate Integration>,地址为:http://aspnetboilerplate.com/Pages/Documents/NHibern ...
- 解决 Eclipse Indigo 3.7、ADT 中文字体偏小,完美 Consolas 微软雅黑混合字体!
Eclipse是著名的跨平台的自由集成开发环境(IDE).6月22日Eclipse 3.7 正式发布,代号是 Indigo . 在 Windows 7 下初始后化,发现界面变化不大,但中文字体却面目全 ...
- JS——图片预览功能
<script type="text/javascript"> function DisplayImage(fileTag) { document. ...
- ASP.NET Core使用EPPlus操作Excel
1.前言 本篇文章通过ASP.NET Core的EPPlus包去操作Excel(导入导出),其使用原理与NPOI类似,导出Excel的时候不需要电脑上安装office,非常好用 2.使用 新建一个AS ...
- Newtonsoft.Json日常用法
原文链接:https://www.cnblogs.com/ZengJiaLin/p/9578794.html
- 批处理系列(14) - 路径/时间/字符切分等DEMO操作
结合本系列文章第一篇,看本文. 本篇熟悉操作文件路径.时间,温习字符切分. 路径 @echo off @REM @Author: xianghongai@gmail.com :GTCONTINUE @ ...
- s11 day Linux 和nginx 部署
https://www.cnblogs.com/pyyu/p/9481344.html ,开机初始化的配置 iptables -F 清空防火墙 /etc/init.d/iptables stop ...
- 记录php漏洞--宇宙最强语言 PHP 爆出 DoS 漏洞,可以直接灌满 CPU
站长之家(Chinaz.com)5月20日消息 近日,PHP被爆出存在远程DOS漏洞,若黑客利用该漏洞构造PoC发起连接,容易导致目标主机CPU被迅速消耗.此漏洞涉及众多PHP版本,因而影响范围极大 ...
- nginx 开启GZIP、域名指向index.html
nginx 虽然默认开启了gzip压缩,但是有关压缩文件.压缩效率没有开启,在建设我的(个人博客)[www.fayinme.cn]中,直观的感受到gzip带来的访问速度提升的快感. 如何开启GZIP ...