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格式读取. 但这时会出现一种情况,第一次读取第一 ...
随机推荐
- 【最大流之Dinic算法】POJ1273 【 & 当前弧优化 & 】
总评一句:Dinic算法的基本思想比较好理解,就是它的当前弧优化的思想,网上的资料也不多,所以对于当前弧的优化,我还是费了很大的功夫的,现在也一知半解,索性就写一篇博客,来发现自己哪里的算法思想还没理 ...
- 相聚 桂林电子科技大学第三届ACM程序设计竞赛
题目链接:https://ac.nowcoder.com/acm/contest/558/D 就是求有多少块区域,用DFS就可以解决,一遇到一个1就从其开始深搜,将其所在的区域块覆灭(变为0),再遇到 ...
- Spring Boot 2 实践记录之 组合注解原理
Spring 的组合注解功能,网上有很多文章介绍,不过都是介绍其使用方法,鲜有其原理解析. 组合注解并非 Java 的原生能力.就是说,想通过用「注解A」来注解「注解B」,再用「注解B」 来注解 C( ...
- update from用法
from:https://www.cnblogs.com/zerocc/archive/2011/11/01/2231841.html update 表名 SET 更新字段 FROM 更新表名(多个 ...
- 创建/读取/删除Session对象
//创建Session对象 Session["userName"] = "顾德博";//保存,这里可以存储任意类型的数据,包括对象.集合等 Session.Ti ...
- C# wpf InkCanvas 保存图片jpg
前端xaml页面代码 <Window x:Class="WpfApplication6.MainWindow" xmlns="http://schemas.micr ...
- bower报错:未能连接到github.com端口1080:超时和一些其他错误
报错1:fatal: unable to access 'https://github.com/xxx/xxxx.git/': Failed to connect to github.com port ...
- C#通过rdp账密直接打开远程桌面
思路是首先新建一个vbs脚本,再创建一个bat脚本,再创建rdp文件,运行顺序是vbs->bat->rdp.rdp文件里面包含远程电脑的账密和其它信息,这样就可以不用再输入账密,而在程序里 ...
- Day 39 管道 、数据共享与地址池
参考张磊同学的博客 http://www.cnblogs.com/chongdongxiaoyu/p/8658379.html 一.管道 #创建管道的类: Pipe([duplex]):在进程之间创建 ...
- CRUSH map 定制实例解析
1.提取已有的CRUSH map ,使用-o参数,ceph将输出一个经过编译的CRUSH map 到您指定的文件ceph osd getcrushmap -o crushmap.txt 2.反编译你的 ...