Questions tagged [embedded-resource]

Resources (such as images and help files) that are embedded into the binary of the application itself and typically not available as files.

Embedded resources are resources such as images and help files that are embedded into the binary of the application itself. Such resources would normally not be available as files. There are methods available for loading resources from URLs or input streams in most languages.

Java

This is how an URL might be formed, that points to an embedded resource within a Jar on the run-time class-path of a Java based app.

URL url = this.getClass().getResource("/path/to/the.resource");

This is how an input stream reading from the embedded resource can be formed:

InputStream is = this.getClass().getResourceAsStream("/path/to/the.resource");

Several detailed tutorials and examples are cited here.

1823 questions
764
votes
23 answers

How to read embedded resource text file

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 user to find and replace text in a text file that is not embedded. private void…
Me.Close
  • 7,691
  • 4
  • 14
  • 6
425
votes
10 answers

Storing WPF Image Resources

For a WPF application which will need 10 - 20 small icons and images for illustrative purposes, is storing these in the assembly as embedded resources the right way to go? If so, how do I specify in XAML that an Image control should load the image…
driis
  • 151,614
  • 43
  • 262
  • 332
289
votes
15 answers

Reading a resource file from within jar

I would like to read a resource from within my jar like so: File file; file = new File(getClass().getResource("/file.txt").toURI()); BufferedReader reader = new BufferedReader(new FileReader(file)); //Read the file and it works fine when running…
Koi
  • 2,993
  • 2
  • 10
  • 5
209
votes
28 answers

Could not find any resources appropriate for the specified culture or the neutral culture

I have two ASP.NET Web projects (ProjectA and ProjectB). When class in ProjectA is instantiating a class of ProjectB which uses a resource file Blah.resx, I get this error: An exception of type 'System.Resources.MissingManifestResourceException'…
dev.e.loper
  • 34,180
  • 71
  • 151
  • 237
130
votes
10 answers

Loop through all the resources in a .resx file

Is there a way to loop through all the resources in a .resx file in C#?
np.
  • 2,239
  • 3
  • 29
  • 35
124
votes
7 answers

How to embed a text file in a .NET assembly?

I would like to embed a text file in an assembly so that I can load the text without having to read it from disk, and so that everything I need is contained within the exe. (So that it's more portable) Is there a way to do this? I assume something…
Adam Haile
  • 29,081
  • 56
  • 180
  • 272
122
votes
13 answers

GetManifestResourceStream returns NULL

This is a C# .NET 4.0 application: I'm embedding a text file as a resource and then trying to display it in a dialog box: var assembly = Assembly.GetExecutingAssembly(); var resourceName = "MyProj.Help.txt"; using (Stream stream =…
Ron
  • 2,075
  • 3
  • 20
  • 30
91
votes
4 answers

What's the difference between a Resource and an Embedded Resource in a C# application?

When should I use one or the other? I'd like all of the files I use in my app (images, sound, xml file, etc.) to be inside of the .exe file so I don't deploy with a bunch of folders and files. Thanks for the info.
Sergio Tapia
  • 36,466
  • 70
  • 175
  • 253
73
votes
7 answers

The view must derive from WebViewPage, or WebViewPage

I'm following Justin Slattery's Plugin Architecture tutorial and trying to adapt it for Razor, instead of WebForm Views. Everything else (controllers, plugin assembly loading, etc) seems to be okay. However, I'm not able to get embedded Razor views…
Nasir
  • 9,529
  • 7
  • 28
  • 38
65
votes
4 answers

Embedding resources in executable using GCC

I'm looking for a way to easily embed any external binary data in a C/C++ application compiled by GCC. A good example of what I'd like to do is handling shader code - I can just keep it in source files like const char* shader = "source here"; but…
Kos
  • 64,918
  • 23
  • 156
  • 223
64
votes
1 answer

How to embed HTML in restructured text file?

I'm using reStructuredText and I'd like to add HTML encoding an interactive flash-type animation through the tag. From my .rst document, how can I specify the position of this arbitrary chunk of HTML? Something like: .. html :: …
user248237
63
votes
3 answers

Loading resources like images while running project distributed as JAR archive

I am having a error for my GUI. Trying to set title bar icon then be included in a Runnable JAR. BufferedImage image = null; try { image = ImageIO.read(getClass().getClassLoader().getResource("resources/icon.gif")); } catch (IOException e) { …
exlux15
  • 861
  • 1
  • 8
  • 16
58
votes
6 answers

How can I extract a file from an embedded resource and save it to disk?

I'm trying to compile the code below using CSharpCodeProvider. The file is successfully compiled, but when I click on the generated EXE file, I get an error (Windows is searching for a solution to this problem) and nothing happens. When I compile…
Rafik Bari
  • 4,473
  • 17
  • 61
  • 121
50
votes
2 answers

File loading by getClass().getResource()

I have followed the way of loading the resource file by using getClass.getResource(path). The snippet of code is here : String url = "Test.properties"; System.out.println("Before printing paths.."); System.out.println("Path2: "+…
AnjanN
  • 543
  • 1
  • 4
  • 9
47
votes
10 answers

How do I add an image to a JButton

I am trying to add an image to a JButton and I'm not sure what I'm missing. When I run the following code the button looks exactly the same as if I had created it without any image attribute. Water.bmp is in the root of my project folder. ImageIcon…
kevinstueber
  • 2,736
  • 3
  • 23
  • 25
1
2 3
99 100