Skip to content

Commit 675c5e9

Browse files
authored
Added in saving encrypted message
Now whenever you do encrypt with ceaser cypher, it will also make a file textE.txt in the same folder as the jar.
1 parent 22ca032 commit 675c5e9

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

Main.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package base;
2+
import java.io.FileNotFoundException;
3+
import java.io.PrintWriter;
24
import java.util.Scanner;
35

46
public class Main {
57

68

7-
public static void main(String[] args) {
9+
public static void main(String[] args) throws FileNotFoundException {
810

911
//Start the object e for AlphaNum encryptions
1012
Encrypt e = new Encrypt();
@@ -51,6 +53,13 @@ public static void main(String[] args) {
5153
System.out.println("Below is encrypted Text with Ceaser Cypher, offset of " + numEi);
5254
System.out.println(encrypted);
5355

56+
//Code to save file to EncryptedT.txt
57+
createfile c = new createfile();
58+
c.openFile();
59+
c.addRecords(encrypted);
60+
c.closeFile();
61+
System.out.println("The encrypted text was saved on EncryptedT.txt");
62+
5463
System.out.println("please reload the application again if you want to do another calculation");
5564

5665
// close the scanner

createfile.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package base;
2+
3+
import java.io.*;
4+
import java.lang.*;
5+
import java.util.*;
6+
7+
public class createfile {
8+
9+
private Formatter x;
10+
11+
public void openFile() {
12+
try{
13+
x = new Formatter("textE.txt");
14+
} catch(Exception e) {
15+
System.out.println("Error with writting to file");
16+
}
17+
}
18+
public void addRecords(String en) {
19+
x.format("%s", en);
20+
21+
}
22+
23+
public void closeFile() {
24+
x.close();
25+
}
26+
27+
}
28+
29+

0 commit comments

Comments
 (0)