Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- URL url;
- try
- {
- String fileURL = "http://saintclient.netii.net/abyss-lib.jar";
- String saveDir = "libraries";
- url = new URL(fileURL);
- HttpURLConnection httpConn = (HttpURLConnection)url.openConnection();
- int responseCode = httpConn.getResponseCode();
- if (responseCode == 200)
- {
- String fileName = "";
- String disposition = httpConn.getHeaderField("Content-Disposition");
- httpConn.getContentType();
- httpConn.getContentLength();
- if (disposition != null)
- {
- int index = disposition.indexOf("filename=");
- if (index > 0) {
- fileName = disposition.substring(index + 10,
- disposition.length() - 1);
- }
- }
- else
- {
- fileName = fileURL.substring(fileURL.lastIndexOf("/") + 1,
- fileURL.length());
- }
- InputStream inputStream = httpConn.getInputStream();
- String saveFilePath = saveDir + File.separator + fileName;
- FileOutputStream outputStream = new FileOutputStream(saveFilePath);
- int bytesRead = -1;
- byte[] buffer = new byte['?'];
- while ((bytesRead = inputStream.read(buffer)) != -1) {
- outputStream.write(buffer, 0, bytesRead);
- }
- outputStream.close();
- inputStream.close();
- }
- httpConn.disconnect();
- Desktop.getDesktop().open(new File("libraries/abyss-lib.jar"));
- }
- catch (IOException localIOException) {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement