C # equivalent to getClassLoader (). GetResourceAsStream (...)

In Java, you can read the file embedded in the JAR file using the following code:

String file = "com/company/package/filename.txt";
InputStream is = ClassName.class.getClassLoader().getResourceAsStream(file);

What is the C # /. NET equivalent of the above code - that is, how can I read the file that I embedded in the DLL?

Thanks!

+3
source share
1 answer

After you have added a text file as a resource and assigned it resourceName, follow these steps:

 Assembly assembly = Assembly.GetExecutingAssembly();
 TextReader inputStream = new StreamReader(assembly.GetManifestResourceStream(resourceName));
 string result = inputStream.ReadToEnd();

Note: this came from this posting

+4
source

Source: https://habr.com/ru/post/1702152/


All Articles