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.

1918 questions
18
votes
5 answers

Load image from a filepath via BufferedImage

I have a problem with Java application, particular in loading a image from a location in my computer. Following this post I used a BufferedImage and a InputFileStream to load an image on my computer. First, I put the image (pic2.jpg) into the source…
Lup
  • 197
  • 1
  • 1
  • 7
18
votes
3 answers

Adding fonts to Swing application and include in package

I need to use custom fonts (ttf) in my Java Swing application. How do I add them to my package and use them? Mean while, I just install them in windows and then I use them, but I don't wish that the usage of the application will be so complicated,…
DanM
  • 1,530
  • 4
  • 23
  • 44
18
votes
6 answers

Including resource file in a project by .RC file rather than .RES file

I remember reading an article or post somewhere years ago that suggested including a resource file in a project by referencing the .rc file instead of an already compiled .res file so that the resource is built as part of the project's build…
lukeck
  • 4,528
  • 3
  • 27
  • 29
17
votes
1 answer

specify build action of content - Nuget

What is the simplest way to tell Nuget package to add all css files as an embedded resource (ie build action is embedded resource). I am trying to do it through install.ps1 in the tools folder but still cant get anywhere Note: I am creating the…
labroo
  • 2,901
  • 3
  • 27
  • 36
17
votes
4 answers

Mono resources.resx problem when porting (strange error in resx xml file on '')

So I have a C# app. It has some assets that are linked into it and are beeng embeded during compile time. App compiles and runs perfectly on windows. when testing for compatabilety with mono tells that all is correct. If I try to compile gives one…
Rella
  • 65,003
  • 109
  • 363
  • 636
16
votes
11 answers

Java getClass().getResource("file") leads to NullPointerException

I am following the Snake Java games tutorial and always get this error: ImageIcon iid = new ImageIcon(this.getClass().getResource("ball.png")); ball = iid.getImage(); Exception in thread "main" java.lang.NullPointerException at…
kapitanluffy
  • 1,269
  • 7
  • 26
  • 54
16
votes
4 answers

WPF - Add Custom Font

I'm trying to add a custom font as a resource in my application. I have a "CustomFont" directory in the application and all the fonts inside of it are set to "Resource"