ini檔是常見的設定檔格式,可參考:https://en.wikipedia.org/wiki/INI_file

讀取檔案很容易直覺想到StreamReader

但其實可以用win32 API有效率的讀寫.ini檔哦

 

  • using System.Runtime.InteropServices;
  • 在class中新增下列code

[DllImport( "kernel32", CharSet = CharSet.Unicode, SetLastError = true )] 
private static extern bool WritePrivateProfileString( string sectionName, string keyName, string keyValue, string filePath );
[DllImport( "kernel32", CharSet = CharSet.Unicode, SetLastError = true )]
private static extern int GetPrivateProfileString( string sectionName, string keyName, string defaultReturnString, StringBuilder returnString, int returnStringLength, string filePath );

PS:WritePrivateProfileString中filePath若沒有寫全路徑似乎會指到C:\windows去


 

 

文章標籤
全站熱搜
創作者介紹
創作者 Milexz 的頭像
Milexz

Dream Chaser <span id="test123">since 1985</span>

Milexz 發表在 痞客邦 留言(0) 人氣(1,511)