Copying a binary file outside of a jar

Sheedlils

New Member
I have an exe packaged inside my jar file and I am trying to copy it to a temporary location so that i can run it using \[code\]Desktop.browse()\[/code\], to do this I set up a scanner with the input stream constructor using \[code\]class.getResourceAsStream\[/code\], and then with a \[code\]printwriter\[/code\] wrote that all to a file. The problem that occurred says that the exe is invalid. I think this is due to some binary data being lost. If anyone can help please post a comment.\[code\] Scanner sc = new Scanner(ClassBuilder.class.getResourceAsStream("jd-gui.exe")); File copy = new File("C://users//Owner//Desktop//java//jd-gui.exe"); copy.createNewFile(); PrintWriter writer = new PrintWriter(copy); while(sc.hasNextLine()) writer.println(sc.nextLine()); writer.flush(); writer.close(); sc.close(); Desktop.getDesktop().browse(copy.toURI()); \[/code\]
 
Back
Top