C 對ini檔案的讀寫操作例項

2022-08-04 21:51:20 字數 1957 閱讀 5624

using system;

using system.io;

using system.runtime.interopservices;

using system.text;

using system.collections;

using system.collections.specialized;

namespace wuyisky

catch

}//必須是完全路徑,不能是相對路徑

filename = fileinfo.fullname;

}//寫ini檔案

public void writestring(string section, string ident, string value)

}//讀取ini檔案指定

public string readstring(string section, string ident, string default)

//讀整數

public int readinteger(string section, string ident, int default)

catch (exception ex)

}//寫整數

public void writeinteger(string section, string ident, int value)

//讀布林

public bool readbool(string section, string ident, bool default)

catch (exception ex)

}//寫bool

public void writebool(string section, string ident, bool value)

//從ini檔案中,將指定的section名稱中的所有ident新增到列表中

public void readsection(string section, stringcollection idents)

private void getstringsfrombuffer(byte buffer, int buflen, stringcollection strings)}}

}//從ini檔案中,讀取所有的sections的名稱

public void readsections(stringcollection sectionlist)

//讀取指定的section的所有value到列表中

public void readsectionvalues(string section, namevaluecollection values)

}/**/////讀取指定的section的所有value到列表中,

//public void readsectionvalues(string section, namevaluecollection values,char splitstring)

////}

//清除某個section

public void erasesection(string section)

}//刪除某個section下的鍵

public void deletekey(string section, string ident)

//note:對於win9x,來說需要實現updatefile方法將緩衝中的資料寫入檔案

//在win nt, 2000和xp上,都是直接寫檔案,沒有緩衝,所以,無須實現updatefile

//執行完對ini檔案的修改之後,應該呼叫本方法更新緩衝區。

public void updatefile()

//檢查某個section下的某個鍵值是否存在

public bool valueexists(string section, string ident)

//確保資源的釋放

~inifiles()

}}

C 對 ini檔案的讀寫操作

1.using system 2.using system.collections.generic 3.using system.runtime.interopservices 4.using system.text 5.6.namespace ini 7.27.28.方法 向ini檔案寫入資料 2...

C 對ini檔案的讀寫操作

解決問題時候,發現ini檔案相對於txt檔案的優點,所以找資料學習了ini檔案的儲存操作 首先是ini檔案的格式 例 張三 名稱 zs 性別 男 設定 顏色 red 模式 1 型別 3 ini檔案由節 鍵 值組成 using system.runtime.interopservices 若此命名空間...

對INI檔案的讀寫

將必要資訊儲存在ini中 相關ini操作如下 在程式中經常要用到設定或者其他少量資料的存檔,以便程式在下一次執行的時候可以使用,比如說儲存本次程式執行時視窗的位置 大小 一些使用者設定的資料等等,在 dos 下程式設計的時候,我們一般自己產生乙個檔案,由自己把這些資料寫到檔案中,然後在下一次執行的時...