读取ini文件 当ini文件里的条数超过1000条的时候,程序是一直向里面写数据一条一条的我删除其中500条,怎么写程序 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 class ReadIni { public static void Main() { ReadIniFile(@"c:\test.ini", 1); } private static void ReadIniFile(string filePath, int readLine) { if (File.Exists(filePath)) { StringBuilder newFile = new StringBuilder(); int fileLineCount = 0; using (StreamReader sr = new StreamReader(File.OpenRead(filePath))) { while (!sr.EndOfStream) { newFile.AppendLine(sr.ReadLine()); fileLineCount++; if (fileLineCount == readLine) break; } } File.Delete(filePath); using (StreamWriter sw = new StreamWriter(File.Create(filePath))) { sw.Write(newFile); } } else { Console.WriteLine("The target file [" + filePath + "] not exists!"); } Console.ReadKey(); } } string[] arr=File.ReadAllLine("");foreaqch(string s in arr){ }一般使用 [DllImport("kernel32")] private static extern long WritePrivateProfileString(string section, string key, string val, string filePath); [DllImport("kernel32")] private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath); 楼上的方法应该挺好 没有试 自己决定多写几个ini来实现,本来的意思就是让读文件的时候更快一些谢谢 各位同仁 调用存储过程的数据集,如何用SqlDataAdapter遍历更新 webbrower中如何自动点网页上的超链接??? lock(myLocker)导致程序异常退出,myLocker不为空 如何获取在folderbrowserdialog选中的文件夹中的文件列表? interface为何还要abstract? 如何在DataGrid选中Row中的Cell的时候选中这一行? 自定义控件的事件 帮忙给个思路 C#中有没有原来C++的默认值 如何在web页面中建立一个textbox控件数组 [原创]C# 数据操作窗体实现增/删/改/查(图) (一) 解决马上给分
{
public static void Main()
{
ReadIniFile(@"c:\test.ini", 1);
} private static void ReadIniFile(string filePath, int readLine)
{
if (File.Exists(filePath))
{
StringBuilder newFile = new StringBuilder();
int fileLineCount = 0;
using (StreamReader sr = new StreamReader(File.OpenRead(filePath)))
{
while (!sr.EndOfStream)
{
newFile.AppendLine(sr.ReadLine());
fileLineCount++;
if (fileLineCount == readLine)
break;
}
} File.Delete(filePath); using (StreamWriter sw = new StreamWriter(File.Create(filePath)))
{
sw.Write(newFile);
}
}
else
{
Console.WriteLine("The target file [" + filePath + "] not exists!");
} Console.ReadKey();
}
}
foreaqch(string s in arr)
{
}
一般使用
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath); [DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
自己决定多写几个ini来实现,本来的意思就是让读文件的时候更快一些
谢谢 各位同仁