I want to create an image file of byte array, image file save in resources folder. Then, i want to show image file in my panel.
I wrote this code, this code works in Eclipse well but when i create a jar file and run jar with command in windows, i get error.
I searched, someone said, i should use getResourceAsStream but i don't know how can use this. Please help me. Thanks
Method for saving image:
public static void saveImage() {
String s="........................";
byte[] dataCustImg = Base64.decode(s.getBytes());
URL url = st.getClass().getClassLoader().getResource("resources/");
File file = new File(url.toURI());
try {
OutputStream stream = new FileOutputStream(file+"/test"
+ sData.getCustID() + ".bmp");
stream.write(dataCustImg);
stream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Error is for below line:
File file = new File(url.toURI());
Error:
Exception in thread "Thread-1" java.lang.IllegalArgumentException: URI is not hi
erarchical
at java.io.File.<init>(Unknown Source)
at com.kit.vip.popup.ServerThread.saveImage(ServerThread.java:114)
at com.kit.vip.popup.ServerThread.run(ServerThread.java:90)
I write byte array to image file inside jar file, this is true?
Thanks for your answers.