-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperations.java
More file actions
34 lines (24 loc) · 865 Bytes
/
Operations.java
File metadata and controls
34 lines (24 loc) · 865 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package cg;
/**
* Created by kreisso on 09.07.2018.
*/
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
public interface Operations {
default public void makeCopies(String source, String destiny, Integer howManyCopies) throws IOException
{
if(!Files.exists(Paths.get(destiny)))
{
Files.createDirectory(Paths.get(destiny));
}
String fileName = new File(source).getName();
int dotIndex = fileName.lastIndexOf('.');
String extension = (dotIndex == -1) ? "" : fileName.substring(dotIndex + 1);
for(int i = 0; i < howManyCopies.intValue(); i++) {
Files.copy(Paths.get(source), Paths.get(destiny+"/"+i+"."+extension), StandardCopyOption.REPLACE_EXISTING);
}
}
}