embedded-resource

File loading by getClass().getResource()

半世苍凉 提交于 2019-11-26 02:05:41
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: "+ getClass().getResource(url).getPath()); FileInputStream inputStream = new FileInputStream(new File(getClass().getResource(url).toURI())); i_propConfig.load(inputStream); inputStream.close(); I have configured it in eclipse with the hierarchy (Under source there is a folder called SwingDemo. In SwingDemo there is my java file as well as the resource file)... src

File loading by getClass().getResource()

僤鯓⒐⒋嵵緔 提交于 2019-11-26 01:00:36
问题 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: \"+ getClass().getResource(url).getPath()); FileInputStream inputStream = new FileInputStream(new File(getClass().getResource(url).toURI())); i_propConfig.load(inputStream); inputStream.close(); I have configured it in eclipse with the hierarchy (Under source there

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

微笑、不失礼 提交于 2019-11-26 00:37:43
问题 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 with the resource files? And if you can, how do you do it and how do you programaticaly load the text into a string? 回答1: Right-click the project file, select Properties. In the window that opens, go to the Resources tab, and if it has just a blue

Java Swing: Displaying images from within a Jar

假装没事ソ 提交于 2019-11-26 00:22:44
问题 When running a Java app from eclipse my ImageIcon shows up just fine. But after creating a jar the path to the image obviously gets screwed up. Is there a way to extract an image from the jar at runtime so I can then open it up? Or, is there a better way to do this? I\'d like to distribute a single jar file if possible. 回答1: To create an ImageIcon from an image file within the same jars your code is loaded: new javax.swing.ImageIcon(getClass().getResource("myimage.jpeg")) Class.getResource

Embedding resources in executable using GCC

孤人 提交于 2019-11-26 00:20:23
问题 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 that\'s extremely impractical. I\'d like the compiler to do it for me: upon compilation (linking stage), read file \"foo.bar\" and link its content to my program, so that I\'d be able to access the contents as binary data from the code. Could be

WPF image resources

醉酒当歌 提交于 2019-11-25 23:26:44
问题 I come from a mostly web and a little bit Windows Forms background. For a new project, we will be using WPF. The WPF application will need 10 - 20 small icons and images for illustrative purposes. I am thinking about storing these in the assembly as embedded resources. Is that the right way to go? How do I specify in XAML that an Image control should load the image from an embedded resource? 回答1: If you will use the image in multiple places, then it's worth loading the image data only once

Loading image resource

故事扮演 提交于 2019-11-25 22:53:56
问题 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) { e.printStackTrace(); } frame.setIconImage(image); Here is the error I am getting: Exception in thread \"main\" java.lang.IllegalArgumentException: input == null! at javax.imageio.ImageIO.read(Unknown Source) at GUI.<init>(GUI.java:39) at GUI.main(GUI

How to read embedded resource text file

橙三吉。 提交于 2019-11-25 21:45:54
问题 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 button1_Click(object sender, EventArgs e) { StringCollection strValuesToSearch = new StringCollection(); strValuesToSearch.Add(\"Apple\"); string stringToReplace; stringToReplace = textBox1.Text; StreamReader FileReader = new StreamReader(@\"C:\\MyFile.txt\"

Reading a resource file from within jar

落爺英雄遲暮 提交于 2019-11-25 21:39:22
问题 I would like to read a resource from within my jar like so: File file; file = new File(getClass().getResource(\"/file.txt\").toURI()); BufferredReader reader = new BufferedReader(new FileReader(file)); //Read the file and it works fine when running it in Eclipse, but if I export it to a jar the run it there is an IllegalArgumentException: Exception in thread \"Thread-2\" java.lang.IllegalArgumentException: URI is not hierarchical and I really don\'t know why but with some testing I found if I