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格式读取. 但这时会出现一种情况,第一次读取第一 ...
随机推荐
- PBOCIC读芯片卡流程
https://blog.csdn.net/kxd_ysheng/article/details/21178101?_t=t PBOCIC读芯片卡流程,参考上面的博客,整理了一下PBOCIC卡读流程. ...
- hdu 1231 最大连续子序列 ,1003 Max Sum;
题目(1231) #include<stdio.h> #include<iostream> using namespace std; int main() { int K,nu ...
- hibernate中常用的Hql语句总结
// HQL: Hibernate Query Language. // 特点: // >> 1,与SQL相似,SQL中的语法基本上都可以直接使用. // >> 2,SQL查询 ...
- Paul and Joyce are going to a movie(More listening of Unit 2)
Paul: Hurry up, Joyce. We need to leave now if we're going to get to the theater a half hour befor ...
- 团队项目(第三周)—GG队
需求改进&系统设计 队员 学号 叶尚文(队长) 3116008802 蔡晓晴 3216008808 杜婷萱 3216008809 龙剑初 3116004647 于泽浩 3116004661 一 ...
- 修改jenkins启动的默认用户
# 背景 通过yum命令安装的jenkins,通过service jenkins去启动jenkins的话,默认的用户是jenkins,但jenkins这个用户是无法通过su切换过去的 ,在某些环节可能 ...
- BlangenOA项目总结
1.使用EF,当返回的是IQueryable<T>类型,延迟加载. 2.增删改查 分页(页码,页大小,总记录数,是否升序)(两个lambda表达式,一个筛选规则,一个是排序规则(可以选择类 ...
- Map 综述(三):彻头彻尾理解 ConcurrentHashMap
https://blog.csdn.net/justloveyou_/article/details/72783008
- Android学习之Fragment解析
1.定义 Fragment中文解释是碎片的意思,主要用在大屏幕设备上,例如平板电脑上,支持更加动态和灵活的UI设计.Fragment在你的应用中相当于是一个模块化和可重用的组件,因为Fragm ...
- TOJ2470
#include <stdio.h> struct node{ int x; int y; int step; }first; int zx[4]={-1,0,1,0}; int zy[4 ...