c#读取文件
来源:互联网 发布:大华网络视频解码器 编辑:程序博客网 时间:2024/05/22 04:55
string s1 = string.Empty;
//读取文件
try
{
FileStream fs = new FileStream("F:\\test.txt", FileMode.Open);
StreamReader sr = new StreamReader(fs);
while (sr.ReadLine() != null)
{
s1 += sr.ReadLine();
}
//string s2 = sr.ReadToEnd();
sr.Close();
}
catch (Exception err)
{
throw new Exception("异常信息为:" + err.Message);
}
finally
{
}
string str1= "";
string str;
try
{
FileStream file = new FileStream("F:\\test.txt", FileMode.Open);
StreamReader sr = new StreamReader(file);
while ((str=sr.ReadLine()) != null)
{
str1 += str;
}
//或者str = sr.ReadToEnd();
sr.Close();
}
catch
{ }
string[] s = File.ReadAllLines("F:\\test.txt");
//string s = textBox3.Text;
//string[] lines = s.Split(new char[] {'\r','\n' }, StringSplitOptions.RemoveEmptyEntries);
string[] lines = textBox3.Lines;
int maxScore = 0;
string Name = string.Empty;
foreach (var line in lines)
{
string[] strs = line.Split('=');
int score = int.Parse(strs[1]);
if (score > maxScore)
{
maxScore = score;
Name = strs[0];
}
}
label1.Text = maxScore.ToString();
/// <summary>
/// 写日志,方便测试,看网站需求(也可以将其写到数据库)
/// </summary>
/// <param name="sPath"></param>
/// <param name="sWord"></param>
public static void log_result(string sPath,string sWord)
{
StreamWriter fs = new StreamWriter(sPath, false, System.Text.Encoding.Default);
fs.Write(sWord);
fs.Close();
}
- c#读取文件一行一行读取
- C# 读取DXF文件
- c#读取ini文件
- c#读取ini文件
- C#读取XML文件
- C#读取文件
- C#读取properties文件
- C#读取DBF文件
- 读取excel文件 C#
- C#读取INI文件
- c#读取excel文件
- C# 读取Excel文件
- C#读取XML文件
- C#读取CSV文件
- C# 读取记事本文件
- C#读取文件
- c#读取资源文件
- C# 读取写入文件
- 一个介绍emacs lisp的个人主页
- 来自老教授的罗嗦
- 二叉树的应用详解 - 数据结构
- Python os模块的Examples
- double类型的精度问题【计算时有误差】。 (0.1 * 0.1 , 1.0 - 0.9)
- c#读取文件
- 西北农林科技大学信息工程学院10级Java考试不标准答案
- HTK在windows 系统下的安装步骤
- java变量与方法总结
- 多继承下的内存布局
- 读STL源码剖析(3)
- mini2440上 移植yaffs2
- C#中using关键字的作用及其用法
- 让Linux下播放CSF格式视频技巧