c# 파일 읽기, 쓰기
@@
c# 파일 읽기, 쓰기
static public string LoadFile(string file)
{
string ret = "";
try
{
ret = System.IO.File.ReadAllText(G.MakeFullPath(file), System.Text.Encoding.GetEncoding("ks_c_5601-1987"));
}
catch { }
return ret;
}
static public bool FileWrite(string file, string s,int offset=0, bool bMakeBak = true)
{
byte[] data = Encoding.Default.GetBytes(s);
return FileWrite(file, data, offset, data.Length, bMakeBak);
}
static public bool FileWrite(string file, byte[] data, int offset, int len, bool bMakeBak = true)
{
bool ret = false;
try
{
if (bMakeBak)
{
C.Rename_bak(file);
}
else
{
C.Unlink(file);
}
System.IO.FileStream f = new System.IO.FileStream(file, System.IO.FileMode.CreateNew);
f.Write(data, offset, len);
f.Close();
ret = true;
}
catch { }
return ret;
}
'C#' 카테고리의 다른 글
c# OnDropFile (0) | 2021.04.07 |
---|---|
c# OnDropFile (0) | 2021.03.21 |
오류 CS0106 이 항목의 'private' 한정자가 유효하지 않습니다. (0) | 2021.01.30 |
문자열 분리(나누기) (0) | 2020.12.19 |
기타등등 (0) | 2020.12.05 |