Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public void onEvent(int event, String path) {
- if (event==DELETE) {
- File file = new File(rootPath, path);
- File otherFile = new File(rootPath, "backup_" + path);
- writeFile(file,otherFile);
- }
- }
- private void writeFile(File inFile, File outFile) {
- Executors.newSingleThreadExecutor()
- .submit(() -> {
- InputStream in;
- OutputStream out;
- try {
- outFile.createNewFile();
- in=new BufferedInputStream(new FileInputStream(inFile));
- out=new BufferedOutputStream(new FileOutputStream(outFile));
- byte[] data = new byte[2048];
- while (in.read(data) > -1) {
- out.write(data);
- }
- in.close();
- out.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement