Reputation: 1683
Ok, so I wanted to open a pdf file that I put it in my jar, so I needed to copy the file from the jar to my disk, and I did so by the following code:
InputStream is = Jar.class.getResourceAsStream("images/lol.pdf");
OutputStream os = new FileOutputStream("753951741.pdf");
byte[] buffer = new byte[4096];
int length;
while ((length = is.read(buffer)) > 0)
os.write(buffer, 0, length);
os.close();
is.close();
my question is:how do I control where the file is created? When I execute the program It's created under C:/Users/Buba Thanks in advance :)
Upvotes: 0
Views: 47
Reputation: 11117
You can do like this:
File file = new File("c:/753951741.pdf");
OutputStream os = new FileOutputStream(file);
In this case the file will be created in C:/
For more information about File in Java: http://docs.oracle.com/javase/6/docs/api/java/io/File.html#File(java.lang.String)
Upvotes: 2