(函数名凭记忆写的,可能不准确,但差不多)
string = File.ReadAll(filename); 获得整个文本
string[] = File.ReadLines(filename); 获得整个文本,每一行作为一个string,放到数组,应该可以满足你的要求,除非文件特别大。
如果你是因为文件比较大,所以要只读取其中某几行的话,那就只能建立一个file对象,一行行的读,不需要的跳过,直到读到你需要的行,因为“行”这个东西没有办法定位。
如果这个需求量很大,可以考虑自己写一个索引文件,把行号对应的文件偏移量保存起来,下一次就直接seek到对应的位置开始读就可以了。
霸王
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace ReadLine_Demo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArg