C# 从内嵌资源读取文件内容 并写入到指定位置

C# 从内嵌资源读取文件内容并写入到指定位置的方法。

String filePath = "test.txt";
System.Reflection.Assembly app = System.Reflection.Assembly.GetExecutingAssembly();
Stream fsOpen = app.GetManifestResourceStream("ResourcesFileRead.fileContent.txt");
FileStream fsSave = new FileStream(filePath, FileMode.Create);
StreamReader sr = new StreamReader(fsOpen);
StreamWriter sw = new StreamWriter(fsSave);
long lenth = sr.BaseStream.Length;
int i = 0;
char[] bytes = new char[256];
while (!sr.EndOfStream)
{
    i = sr.Read(bytes, 0, 256);
    sw.Write(bytes, 0, i);
}
sw.Flush();
sw.Close();
sr.Close();
fsSave.Close();
fsOpen.Close();

暂无评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注

验证码已失效,请刷新验证码