How to read embedded resource text file

前端 未结 22 2409
悲&欢浪女
悲&欢浪女 2020-11-21 06:03

How do I read an embedded resource (text file) using StreamReader and return it as a string? My current script uses a Windows form and textbox that allows the

22条回答
  •  自闭症患者
    2020-11-21 06:40

    I wanted to read the embedded resource just as a byte array (without assuming any specific encoding), and I ended up using a MemoryStream which makes it very simple:

    using var resStream = assembly.GetManifestResourceStream(GetType(), "file.txt");
    var ms = new MemoryStream();
    await resStream .CopyToAsync(ms);
    var bytes = ms.ToArray();
    

提交回复
热议问题