首页  ·  知识 ·  编程语言
读写外部的资源文件
网友    .NET  编辑:德仔   图片来源:网络
另外一种方式就是做成外部的资源文件,这样就可读可写了,在这里贴一些代码 引用 using System.Resources;
另外一种方式就是做成外部的资源文件,这样就可读可写了,在这里贴一些代码
引用 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(); 
 
以上注释的代码都可以打开使用
 
读资源文件的代码
 
            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();
 
本文作者:网友 来源:网络
CIO之家 www.ciozj.com 微信公众号:imciow
   
免责声明:本站转载此文章旨在分享信息,不代表对其内容的完全认同。文章来源已尽可能注明,若涉及版权问题,请及时与我们联系,我们将积极配合处理。同时,我们无法对文章内容的真实性、准确性及完整性进行完全保证,对于因文章内容而产生的任何后果,本账号不承担法律责任。转载仅出于传播目的,读者应自行对内容进行核实与判断。请谨慎参考文章信息,一切责任由读者自行承担。
延伸阅读