Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package th.in.oneauthen;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.nio.file.Files;
- import java.nio.file.Paths;
- import java.util.Base64;
- public class testDecodePdf {
- public static void main(String[] args) throws IOException {
- String filePath = "C:\\user\\Desktop\\dir1\\dir2\\";
- String filePathDes = "C:\\user\\Desktop\\dir1\\";
- File folder = new File(filePath);
- File[] listOfFiles = folder.listFiles();
- if (folder.isDirectory()) {
- if (folder.list().length > 0) {
- for (File file : listOfFiles) {
- if (file.isFile()) {
- byte[] input_file = Files.readAllBytes(Paths.get(filePath + file.getName()));
- byte[] encodedBytes = Base64.getEncoder().encode(input_file);
- String encodedString = new String(encodedBytes);
- byte[] decodedBytes = Base64.getDecoder().decode(encodedString.getBytes());
- FileOutputStream fos = new FileOutputStream(filePathDes + file.getName());
- fos.write(decodedBytes);
- fos.flush();
- fos.close();
- System.out.println(file.getName());
- String Del = filePath + file.getName();
- Files.delete(Paths.get(Del));
- }
- }
- } else {
- System.out.println("Directory is empty!");
- }
- } else {
- System.out.println("This is not a directory");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement