使用C#读写外部的资源文件
来源:互联网 发布:游戏耳机知乎 编辑:程序博客网 时间:2024/05/04 16:06
两天由于程序的需要,有些资源需要使用,想放在资源文件中,在网上查了一些资料,发些资源文件的使用有几种方式,比如像利用资源文件实现多语言版本程序的情况,但这种资源文件的使用一般是嵌入到程序中,只能读,还没有查到可写的资料。
另外一种方式就是做成外部的资源文件,这样就可读可写了,在这里贴一些代码
引用 using System.Resources;
写资源文件代码如下:
ResourceWriter rw = new ResourceWriter("Greeting1.dll");
Bitmap b = new Bitmap("hhw.gif");
//add some strings to the file
//rw.AddResource("Greeting", "Welcome to Microsoft .Net Framework!Test");
//rw.AddResource("PasswordException", "Sorry, that is not the correct password.");
//rw.AddResource("Purchase", "Please select an item to purchase from the store:");
//rw.AddResource("Goodbye", "Thank you for visiting Microsoft .Net Framework!");
rw.AddResource("flag",b );
rw.Generate();
rw.Close();
Bitmap b = new Bitmap("hhw.gif");
//add some strings to the file
//rw.AddResource("Greeting", "Welcome to Microsoft .Net Framework!Test");
//rw.AddResource("PasswordException", "Sorry, that is not the correct password.");
//rw.AddResource("Purchase", "Please select an item to purchase from the store:");
//rw.AddResource("Goodbye", "Thank you for visiting Microsoft .Net Framework!");
rw.AddResource("flag",b );
rw.Generate();
rw.Close();
以上注释的代码都可以打开使用
读资源文件的代码
ResourceReader rr = new ResourceReader("Greeting1.dll");
String s = "";
//iterate through the reader, printing out the name-value pairs
foreach (DictionaryEntry d in rr)
{
Console.WriteLine(d.Key + ":" + d.Value.ToString ()) ;
if (d.Key.ToString () == "flag")
{
Bitmap b = new Bitmap((Bitmap)d.Value);
b.Save("a.gif");
break;
}
}
//close the reader
rr.Close();
String s = "";
//iterate through the reader, printing out the name-value pairs
foreach (DictionaryEntry d in rr)
{
Console.WriteLine(d.Key + ":" + d.Value.ToString ()) ;
if (d.Key.ToString () == "flag")
{
Bitmap b = new Bitmap((Bitmap)d.Value);
b.Save("a.gif");
break;
}
}
//close the reader
rr.Close();
- 使用C#读写外部的资源文件
- C#下面读写资源文件
- C# 资源文件的使用
- C# 资源文件的使用
- spring中PropertyPlaceholderConfigurer的使用,引入外部资源文件
- C# 文件读写与内存资源泄漏
- 使用C#工程里的资源文件
- C#文件的读写
- c#文件的读写
- c#文件的读写
- C#使用FileStream文件读写
- 外部存储读写文件
- IO流,外部与内部文件的读写,API寻找到文件,外部读写权限
- C#中使用资源文件
- C#使用DOM进行XML文件的读写操作介绍
- C# 使用API读写Ini文件的类
- (转载)C#文件的读写
- C#文件的读写 -流
- MFC数据类型(Data Type)
- sql 相关
- 使用刻录机时的注意事项
- android中获取手机分辨率
- test
- 使用C#读写外部的资源文件
- u-boot 自引导内核
- 【转】马云的精典语录
- 电脑死机故障面面观
- 老婆是个维权斗士
- 笑谈协同OA的功能
- 雾水
- 人生32语
- 成功刻录光盘的10则技巧