-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadfile.java
More file actions
49 lines (36 loc) · 1.12 KB
/
readfile.java
File metadata and controls
49 lines (36 loc) · 1.12 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
49
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class readfile {
public String readFile() {
String data = "";
try {
File myObj = new File("password.txt");
Scanner myReader = new Scanner(myObj);
while (myReader.hasNextLine()) {
data = myReader.nextLine();
return data;
}
myReader.close();
} catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
return data;
}
public String encryption() {
String encrypt = readFile();
String correctPassword = "";
char[] chars = encrypt.toCharArray();
for (char c : chars) {
if (c == 'z') {
c = 'a';
correctPassword = correctPassword + c;
} else {
c = (char) (c + 1);
correctPassword = correctPassword + c;
}
}
return correctPassword;
}
}