-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMachine.java
More file actions
48 lines (37 loc) · 1.15 KB
/
Machine.java
File metadata and controls
48 lines (37 loc) · 1.15 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package CryptMachine;
import java.io.*;
import java.util.*;
public class Machine {
private static Machine instance;
private File file;
private String path;
private String newPath;
private Machine (String path) throws IOException {
this.path = path;
this.newPath = path.substring(0, path.lastIndexOf("\\"));
String name = path.substring(path.lastIndexOf("\\")+1, path.lastIndexOf("."));
File directory = new File(newPath);
if (directory.isDirectory())
this.file = File.createTempFile(name, ".txt", directory);
}
public static Machine getInstance (String path) throws IOException {
instance = new Machine(path);
return instance;
}
public File getFile() {
return this.file;
}
public String getPath () {
return this.path;
}
public void encrypt () throws IOException {
Crypt crypt = new Crypt (this.path, this.file);
crypt.processFile();
System.out.println("File successfuly encrypt: " + this.file.getPath());
}
public void decrypt () throws IOException {
Decrypt decrypt = new Decrypt (this.path, this.file);
decrypt.processFile();
System.out.println("File successfuly encrypt: " + this.file.getPath());
}
}