如何写入资源文件? [英] How to write to a resource file?

查看:172
本文介绍了如何写入资源文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果可以从源文件中读取,像这样:

  string fileContent = Resources.Users; 

使用(var reader = new StringReader(fileContent))
{
string line; ((line = reader.ReadLine())!= null)
{
string [] split = line.Split('|');
string name = split [0];
string last = split [1];


$ b $ / code $ / pre

那你怎么写到相同的文件?

解决方案

您可以使用 ResourceWriter
我也建议你使用 ResourceManager 从文件中读取。



代码来自链接源代码:

  using System; 
使用System.Resources;

public class WriteResources {
public static void Main(string [] args){

//创建一个资源编写器。
IResourceWriter writer = new ResourceWriter(myResources.resources);

//将资源添加到资源编写器。
writer.AddResource(String 1,First String);

writer.AddResource(String 2,Second String);

writer.AddResource(String 3,Third String);

//将资源写入文件或流,并关闭它。
writer.Close();
}
}


If it is possible to read from a source file, like this:

string fileContent = Resources.Users;

using (var reader = new StringReader(fileContent))
{
    string line;
    while ((line = reader.ReadLine()) != null)
    {
        string[] split = line.Split('|');
        string name = split[0];
        string last = split[1];

    }
}

Then how can you write to the same file?

解决方案

You can make use of the ResourceWriter . I'd also suggest that you make use of the ResourceManager to read from the file.

Code from the link source:

using System;
using System.Resources;

public class WriteResources {
   public static void Main(string[] args) {

  // Creates a resource writer.
  IResourceWriter writer = new ResourceWriter("myResources.resources");

  // Adds resources to the resource writer.
  writer.AddResource("String 1", "First String");

  writer.AddResource("String 2", "Second String");

  writer.AddResource("String 3", "Third String");

  // Writes the resources to the file or stream, and closes it.
  writer.Close();
   }
}

这篇关于如何写入资源文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆