• c# 读取嵌入式文件


    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Reflection;
    using System.Text;
    using System.Threading.Tasks;

    namespace zhang_Test
    {
    class Program
    {
    private static void Main(string[] args)
    {


    InitSchemes dd = new InitSchemes();
    string ddds = dd.GetInitSchemes(null);
    }

    }
    /// <summary>
    /// 出厂原始数据
    /// </summary>
    public class InitSchemes
    {
    public string GetInitSchemes(Assembly resourceAssembly = null, string resourceName = "zhang_Test.test.txt")
    {
    if (resourceAssembly == null)
    {
    resourceAssembly = this.GetType().Assembly;
    }

    string json = resourceAssembly.Resource(resourceName);


    return json;
    }
    }
    public static class AssemblyExtensions
    {
    public static string Resource(this Assembly self, string name, Encoding encoding = null)
    {

    var stream = self.GetManifestResourceStream(name);
    if (stream == null)
    {
    return null;
    }

    if (!stream.CanRead)
    {
    return string.Empty;
    }

    //结果
    var result = string.Empty;
    using (var streamReader = encoding != null ? new StreamReader(stream, encoding) : new StreamReader(stream, Encoding.UTF8))
    {
    result = streamReader.ReadToEnd();
    }

    return result;
    }
    }
    }

  • 相关阅读:
    时间工时累加
    python读取mnist
    开始学习haskell
    pip升级所有packages
    ImportError: numpy.core.multiarray failed to import
    NumPy for MATLAB users
    Spyder
    初学ObjectiveC
    Matlab闭包
    ObjeciveC 内存管理
  • 原文地址:https://www.cnblogs.com/zhtbk/p/4692295.html
Copyright © 2020-2023  润新知