import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Base64;
public class Base64FileHandler {
public static void main(String[] args) {
String originalFile = "path/to/original/file.txt";
String encodedFile = "path/to/encoded/file.txt";
String decodedFile = "path/to/decoded/file.txt";
try {
encodeFile(originalFile, encodedFile);
decodeFile(encodedFile, decodedFile);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void encodeFile(String originalFile, String encodedFile) throws IOException {
byte[] fileContent = Files.readAllBytes(Paths.get(originalFile));
byte[] encodedContent = Base64.getEncoder().encode(fileContent);
Files.write(Paths.get(encodedFile), encodedContent);
}
public static void decodeFile(String encodedFile, String decodedFile) throws IOException {
byte[] encodedContent = Files.readAllBytes(Paths.get(encodedFile));
byte[] decodedContent = Base64.getDecoder().decode(encodedContent);
Files.write(Paths.get(decodedFile), decodedContent);
}
}