zoukankan      html  css  js  c++  java
  • C# 读写外部的资源文件

    前两天由于程序的需要,有些资源需要使用,想放在资源文件中,在网上查了一些资料,发些资源文件的使用有几种方式,比如像利用资源文件实现多语言版本程序的情况,但这种资源文件的使用一般是嵌入到程序中,只能读,还没有查到可写的资料。

    另外一种方式就是做成外部的资源文件,这样就可读可写了,在这里贴一些代码

    引用 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();
  • 相关阅读:
    [kuangbin带你飞]专题二十一 概率&期望
    [kuangbin带你飞]专题二十 斜率DP
    POJ——3984迷宫问题(BFS+回溯)
    POJ——2251Dungeon Master(三维BFS)
    HDU——2647Reward(DFS或差分约束)
    HDU——4549M斐波那契数列(矩阵快速幂+快速幂+费马小定理)
    PAT天梯赛练习题——L3-008. 喊山(邻接表+BFS)
    Opencv学习笔记——视频高斯模糊并分别输出
    Opencv学习笔记——视频进度条的随动
    NYOJ——239月老的难题(二分图最大匹配)
  • 原文地址:https://www.cnblogs.com/szyicol/p/1454586.html
Copyright © 2011-2022 走看看