zoukankan      html  css  js  c++  java
  • 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;
    }
    }
    }

  • 相关阅读:
    将博客搬至CSDN
    JDBC
    Java刷题常用API
    Java的反射机制
    Java的IO流
    Docker原理:Cgroup
    Docker原理:Namespace
    Anaconda软件安装使用问题
    初步了解Unix系统的I/O模式
    深入理解索引和AVL树、B-树、B+树的关系
  • 原文地址:https://www.cnblogs.com/zhtbk/p/4692295.html
Copyright © 2011-2022 走看看