当ini文件里的条数超过1000条的时候,程序是一直向里面写数据一条一条的
我删除其中500条,怎么写程序

解决方案 »

  1.   

    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();
            }
        }
      

  2.   

    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);
      

  3.   

    楼上的方法应该挺好 没有试 
    自己决定多写几个ini来实现,本来的意思就是让读文件的时候更快一些
    谢谢 各位同仁