Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2014
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. String resourcePath = "Lobby/src/messages.yml";
  2. String targetFolder = "plugins/Lobby/messages.yml";
  3. String dataFolder = "Lobby";
  4.  
  5. public boolean saveResourceToPath(String resourcePath, String targetFolder) {
  6. java.io.InputStream in = getResource(resourcePath);
  7. if(in == null)
  8. return false;
  9.  
  10. int lastIndex = resourcePath.lastIndexOf('/');
  11. File outDir = new File(dataFolder, resourcePath.substring(0, lastIndex >= 0 ? lastIndex : 0));
  12. if(!outDir.exists())
  13. outDir.mkdirs();
  14. File outFile = new File(targetFolder, resourcePath);
  15. try {
  16. if (!outFile.exists()) {
  17. OutputStream out = new FileOutputStream(outFile);
  18. byte[] buf = new byte[1024];
  19. int len;
  20. while ((len = in.read(buf)) > 0) {
  21. out.write(buf, 0, len);
  22. }
  23. out.close();
  24. in.close();
  25. } else {
  26. return false;
  27. }
  28. } catch (IOException ex) {
  29. return false;
  30. }
  31. return true;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement