embedded-resource

Copying embedded resource as file to disk in C#

强颜欢笑 提交于 2019-11-29 18:48:33
问题 I have an INF file saved as an embedded resource in my C# project. I am trying to save this file to a local location on demand. I am using this method. public static void SaveResourceToDisk(string ResourceName, string FileToExtractTo) { Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream(ResourceName); FileStream resourceFile = new FileStream(FileToExtractTo, FileMode.Create); byte[] b = new byte[s.Length + 1]; s.Read(b, 0, Convert.ToInt32(s.Length)); resourceFile.Write(b, 0,

Problems with images when compiled

点点圈 提交于 2019-11-29 16:58:17
I have been all over the internet trying to work out how to get an image icon displayed after compiling into a runnable jar. I discovered this problem way too late, I ran my program many times before in eclipse and every thing has worked, now 6 months later with project finished, I compiled my program with eclipse and no audio or images work. Reading on the net, it says about the location of images folder should be inside jar, but mine doesnt get put there? I have played around with the images folder moving it inside the source folder, but it didn't work. I have a feeling that it might be

Java Swing: unable to load image using getResource

蓝咒 提交于 2019-11-29 16:22:38
I'm trying to isolate where the problem could be when trying to add an image to the class directory. (Doing this so when I export as a runnable JAR, the image is included in the package). So I've got the strawberry.jpg file sitting in 'C:\Users\sean\workspace\myApps\src\testing' Could you advise what I'm missing? Thanks! package testing; import java.awt.*; import javax.swing.*; public class IconTest { public static void main(String[] arguments) { JFrame frame1 = new JFrame(); frame1.setTitle("Frame1"); frame1.setSize(500, 500); frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); FlowLayout

Read a file within a jar from java code present in same jar

风流意气都作罢 提交于 2019-11-29 16:17:19
I am trying to read a xsd file kept in a jar using java code kept inside the same jar. I am using the following code. URL tmpurl = ClassLoader.getSystemResource("com/abc/filename.xsd"); Schema s = schemaFactory.newSchema(tmpurl); jaxbUnMarshaller.setSchema(s); It is working fine when I run it as a separate project but when I make a jar, tmpurl is null, hence the setSchema gives a null pointer exception. Can you please a workaround that can make it run even inside a jar file. Nikolay Kuznetsov Hava you tried? getClass().getClassLoader().getResource() Also your classpath in manifest file in jar

how to access resources(Excel file) in jar file

爱⌒轻易说出口 提交于 2019-11-29 15:07:14
Hi i have exported my java project as executable jar file. inside my project I am accessing a Excel file containing some data. Now I am not able to access the Excel file when I am trying to access the file. My project structure is: Java_Project_Folder - src_Folder - resources_Folder(Containing excel file) I am accessing the excel file like FileInputStream file=new FileInputStream(new File(System.getProperty("user.dir") +File.separator+"resources"+File.separator+"Excel.xlsx")); I have tried accessing this file using getResourceAsStream like: FileInputStream file=(FileInputStream) this.getClass(

Embedded Database in Qt

那年仲夏 提交于 2019-11-29 13:48:07
I have a SQLite database for my Qt application. I assume that it would be logical to add the database as a resource. I can't get my app to compile with the embedded resource. connection.h #ifndef CONNECTION_H #define CONNECTION_H #include <QMessageBox> #include <QSqlDatabase> #include <QSqlError> #include <QSqlQuery> static bool createConnection() { QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName(":/data/ShippingData.db3"); if (!db.open()) { QMessageBox::critical(0, QObject::tr("Database Error"), db.lastError().text()); return false; } return true; } #endif //

Load image from a filepath via BufferedImage

这一生的挚爱 提交于 2019-11-29 13:21:52
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 code and that is working. However, if I put the image to another place (let's say C:\\ImageTest\pic2.jpg ), Java IDE show me an IllegalArgumentException return ImageIO.read(in); here is the code: public class MiddlePanel extends JPanel { private BufferedImage img; public MiddlePanel(int width) { //img = getImage("pic2.jpg"); img = getImage("C:\

How To Write To An Embedded Resource?

僤鯓⒐⒋嵵緔 提交于 2019-11-29 11:53:54
I keep getting the error "Stream was not writable" whenever I try to execute the following code. I understand that there's still a reference to the stream in memory, but I don't know how to solve the problem. The two blocks of code are called in sequential order. I think the second one might be a function call or two deeper in the call stack, but I don't think this should matter, since I have "using" statements in the first block that should clean up the streams automatically. I'm sure this is a common task in C#, I just have no idea how to do it... string s = ""; using (Stream

Can I modify the content of an embedded resource (text/xml file) in a .NET application

喜夏-厌秋 提交于 2019-11-29 11:45:12
The title is pretty much the question :-) I've embedded an xml file and a txt file as resources in my .NET app. Am still debugging other things, so cannot run and test this. So just asking, would I be able to modify these files at runtime, after deployment? Nope. An embedded resource is a set of bytes in the assembly. Its like trying to modify the code in your assembly, after compiling. This would be doubly bad if your assembly has been signed. If you're trying to swap resources in and out, you can move your resources into a separate ( satellite ) assembly, and swap that assembly at deployment

java getResource() not working

断了今生、忘了曾经 提交于 2019-11-29 11:35:16
this is driving me crazy. I have a NetBeans project in a folder with the following structure: MyProject ---- build ---- src ---- resources in src my code is in packages. What I am trying to do is to use getClass().getResource("/resources/new.png"); from a class in package com.my.package but it just refuses to work! The "new.png" image is in the resources folder. Am I missing something here? After a lot of playing around and moving the "new.png" image here and there to see when it will find the image, it finally worked but only when I put the image in the build folder. So what do I have to do