Advertisement
ballchaichana

testTask

Aug 30th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. package th.in.oneauthen;
  2.  
  3. import java.io.File;
  4. import java.io.FileOutputStream;
  5. import java.io.IOException;
  6. import java.nio.file.Files;
  7. import java.nio.file.Paths;
  8. import java.util.Base64;
  9.  
  10. public class testDecodePdf {
  11.     public static void main(String[] args) throws IOException {
  12.         String filePath = "C:\\user\\Desktop\\dir1\\dir2\\";
  13.         String filePathDes = "C:\\user\\Desktop\\dir1\\";
  14.  
  15.         File folder = new File(filePath);
  16.         File[] listOfFiles = folder.listFiles();
  17.         if (folder.isDirectory()) {
  18.             if (folder.list().length > 0) {
  19.                 for (File file : listOfFiles) {
  20.                     if (file.isFile()) {
  21.                         byte[] input_file = Files.readAllBytes(Paths.get(filePath + file.getName()));
  22.  
  23.                         byte[] encodedBytes = Base64.getEncoder().encode(input_file);
  24.                         String encodedString = new String(encodedBytes);
  25.                         byte[] decodedBytes = Base64.getDecoder().decode(encodedString.getBytes());
  26.  
  27.                         FileOutputStream fos = new FileOutputStream(filePathDes + file.getName());
  28.                         fos.write(decodedBytes);
  29.                         fos.flush();
  30.                         fos.close();
  31.                         System.out.println(file.getName());
  32.                         String Del = filePath + file.getName();
  33.                         Files.delete(Paths.get(Del));
  34.  
  35.                     }
  36.  
  37.                 }
  38.             } else {
  39.  
  40.                 System.out.println("Directory is empty!");
  41.  
  42.             }
  43.         } else {
  44.  
  45.             System.out.println("This is not a directory");
  46.         }
  47.     }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement