Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. @Override
  2. public void onEvent(int event, String path) {
  3. if (event==DELETE) {
  4. File file = new File(rootPath, path);
  5. File otherFile = new File(rootPath, "backup_" + path);
  6. writeFile(file,otherFile);
  7. }
  8. }
  9.  
  10. private void writeFile(File inFile, File outFile) {
  11. Executors.newSingleThreadExecutor()
  12. .submit(() -> {
  13. InputStream in;
  14. OutputStream out;
  15. try {
  16. outFile.createNewFile();
  17. in=new BufferedInputStream(new FileInputStream(inFile));
  18. out=new BufferedOutputStream(new FileOutputStream(outFile));
  19. byte[] data = new byte[2048];
  20. while (in.read(data) > -1) {
  21. out.write(data);
  22. }
  23. in.close();
  24. out.close();
  25. } catch (Exception e) {
  26. e.printStackTrace();
  27. }
  28. });
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement