I want to copy my jar file from where ever to %appdata%!
here is my code:
private void copy() throws IOException {
InputStream is = getClass().getResourceAsStream("client.jar");
OutputStream os = new FileOutputStream("%appdata%/client.jar");
byte[] buffer = new byte[4096];
int length;
while ((length = is.read(buffer)) > 0) {
System.out.println(buffer[length]);
os.write(buffer, 0, length);
}
os.close();
is.close();
}
and get this error:
java.io.FileNotFoundException: %appdata%\client.jar (The system cannot find the path specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at necro.green.client.Client.copy(Client.java:99)
at necro.green.client.Client.main(Client.java:87)
I know my code is crap, so please help!
Edit:
Files.copy(Paths.get("client.jar"), Paths.get(System.getProperty("user.home") + "/AppData/Roaming/client.jar"));
This works thanks to : BurntPizza and Kefwar