Hopewelljnj 46 Share Posted May 30, 2016 Is the picture in a different package than the main script? Link to comment Share on other sites More sharing options...
Opoz 0 Author Share Posted May 30, 2016 So quick recap, making a url object, its returning file:/C:/Users/Jesse/DreamBot/Scripts/hoWoodcutter.jar!/hoWoodcutter/resources/paint.png from getPath(). All good, all is working. Then I do .openStream() ON THAT SAME OBJECT, and it says JAR entry hoWoodcutter/resources/paint.png not found in C:\Users\Jesse\DreamBot\Scripts\hoWoodcutter.jar. Am I stupid or does that contradict itself? Is the picture in a different package than the main script? The main script is just in src->hoWoodcutter Link to comment Share on other sites More sharing options...
Hopewelljnj 46 Share Posted May 30, 2016 So quick recap, making a url object, its returning file:/C:/Users/Jesse/DreamBot/Scripts/hoWoodcutter.jar!/hoWoodcutter/resources/paint.png from getPath(). ---First what is the ! in there? All good, all is working. Then I do .openStream() ON THAT SAME OBJECT, and it says JAR entry hoWoodcutter/resources/paint.png not found in C:\Users\Jesse\DreamBot\Scripts\hoWoodcutter.jar. Am I stupid or does that contradict itself? The main script is just in src->hoWoodcutter ---- try moving the picture into a seperate folder. Like call it pictures or something Link to comment Share on other sites More sharing options...
Opoz 0 Author Share Posted May 30, 2016 So quick recap, making a url object, its returning file:/C:/Users/Jesse/DreamBot/Scripts/hoWoodcutter.jar!/hoWoodcutter/resources/paint.png from getPath(). ---First what is the ! in there? All good, all is working. Then I do .openStream() ON THAT SAME OBJECT, and it says JAR entry hoWoodcutter/resources/paint.png not found in C:\Users\Jesse\DreamBot\Scripts\hoWoodcutter.jar. Am I stupid or does that contradict itself? The main script is just in src->hoWoodcutter ---- try moving the picture into a seperate folder. Like call it pictures or something I moved the image to a package in a folder I have called resources which is in the build path, and the package inside of it is called images. Same issue. It finds paint.png the url constructs, has the correct getPath() but when it tries to openStream() it says it does not exist. Error: JAR entry image/paint.png not found in C:\Users\Jesse\DreamBot\Scripts\hoWoodcutter.jar Location: file:/C:/Users/Jesse/DreamBot/Scripts/hoWoodcutter.jar!/image/paint.png I am passing the filename into my method as "/image/paint.png", is this wrong or incompatible with URL.openStream() somehow? I tried using double backslashes but it just never found the image. Link to comment Share on other sites More sharing options...
Hopewelljnj 46 Share Posted May 30, 2016 do /resources/images/paint.png try that see what happens Link to comment Share on other sites More sharing options...
Opoz 0 Author Share Posted May 30, 2016 do /resources/images/paint.png try that see what happens When you compile it into a jar it combines the contents from all the build paths. Link to comment Share on other sites More sharing options...
Cardozz 46 Share Posted May 30, 2016 So I tried and realized that the if is never actually being run. So apparently myFile exists. I have no clue what is happening anymore. Edit: I believe on that first run it created the file name I put for the temp file, but never got to deleting it because it threw an error. Edit 2: Also I have to change the ClassLoader stuff to just getClass().getResourceAsStream() or it always returns null. If I search for the image using getResource() it works, if I search using getResourceAsStream() it returns null. Like i said: just make up a name so that the if-statement is true. It executes the if-statement only if the file == null. So search for a file that is null xD Try this code: if (Desktop.isDesktopSupported()) { try { File myFile = new File(("ppaint.png")); //Instead of paint.png (the file you look for), look for a file that doesn't exist. if (!myFile.exists()) { //Because here you will execute the body below if the file does not exist! // In JAR InputStream inputStream = ClassLoader.getSystemClassLoader() .getResourceAsStream("resources/paint.png"); //beware of package "resources" // Copy file OutputStream outputStream = new FileOutputStream(myFile); byte[] buffer = new byte[1024]; int length; while ((length = inputStream.read(buffer)) > 0) { outputStream.write(buffer, 0, length); } outputStream.close(); inputStream.close(); } Desktop.getDesktop().open(myFile); } catch (IOException ex) { // no application registered for png views } } I forgot to mention that this code will OPEN the file, but when it opens the pictogram, it means that the code is working If the code works, just delete the "Desktop.getDesktop().open(myFile);" line so it won't open the file Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.