Reputation: 909
I'm packing a .exe with the other resources on my jar, and the I extract it with the following code:
InputStream program=getClass().getResourceAsStream("/program.exe");
try {
FileOutputStream output=new FileOutputStream("C:\\Users\\Aitor\\Desktop\\program.exe");
int b;
while ((b=program.read())!=1)
{
output.write(b);
}
output.close();
} catch (IOException e) {
e.printStackTrace();
}
But i've i try to execute the the exe that is generated, i get an error saying that that archive's version isn't compatible with the windows version I'm using. How can i extract an exe from the jar without corrupting it?
Upvotes: 0
Views: 68
Reputation: 5267
I'd use a faster way of reading and writing the file:
FileOutputStream output=new FileOutputStream("C:\\Users\\Aitor\\Desktop\\program.exe");
int b = 0;
byte[] buff = new byte[1024];
while ((b=program.read(buff))>=0)
{
output.write(buff, 0, b);
}
output.close();
Upvotes: 1