0% found this document useful (0 votes)
4 views2 pages

File EncryptionDecryption

The document is a Java program for file encryption and decryption. It prompts the user to choose between encryption and decryption, then processes the specified input file and writes the result to an output file. The program handles file reading and writing, and provides error handling for invalid choices and file not found scenarios.

Uploaded by

syy40176
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

File EncryptionDecryption

The document is a Java program for file encryption and decryption. It prompts the user to choose between encryption and decryption, then processes the specified input file and writes the result to an output file. The program handles file reading and writing, and provides error handling for invalid choices and file not found scenarios.

Uploaded by

syy40176
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import [Link].

*;
import [Link];

public class FileEncryptionDecryption {


public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);

[Link]("File Encryption/Decryption ");


[Link]("Choose one task (1 for encryption, 2 for decryption): ");
int choice = [Link]();

if (choice != 1 && choice != 2) {


[Link]("Invalid choice. Please enter 1 for encryption or 2
for decryption.");
return;
}

[Link]("Enter the input fileName: ");


String inputFileName = [Link]();
[Link]("Enter the output fileName: ");
String outputFileName = [Link]();

try {
File inputFile = new File(inputFileName);
File outputFile = new File(outputFileName);

if (![Link]()) {
[Link]("file not found");
return;
}

BufferedReader reader = new BufferedReader(new FileReader(inputFile));


BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile));

if (choice == 1) {
// Encryption
String line;
while ((line = [Link]()) != null) {
String encryptedLine = encrypt(line);
[Link](encryptedLine);
[Link]();
}
[Link]("the Encryption completed.");
} else if (choice == 2) {
// Decryption
String line;
while ((line = [Link]()) != null) {
String decryptedLine = decrypt(line);
[Link](decryptedLine);
[Link]();
}
[Link]("the Decryption completed.");
}

[Link]();
[Link]();
} catch (IOException e) {
[Link]("An error has been occurred: " + [Link]());
}
}
OUTPUT:
File Encryption/Decryption
Choose one task (1 for encryption, 2 for decryption): 1
Enter the input fileName: [Link]
Enter the output fileName: [Link]
the Encryption completed.

You might also like