package encrypt; import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.logging.Level; import java.util.logging.Logger; import sun.misc.BASE64Decoder; import sun.misc.BASE64Encoder; /** * * @author GAYAN */ public class Encrypt { /** * @param args the command line arguments */ public static void main(String[] args) { File n = new File("C:\\Users\\Shashika\\Desktop\\enc"); File[] listFiles = n.listFiles(); for (File file : listFiles) { InputStream is = null; OutputStream os = null; try { BASE64Encoder bs = new BASE64Encoder(); System.out.println(file.getName()); is = new FileInputStream(file); // os=new FileOutputStream(file); byte[] bs1 = null; try { bs1 = new byte[is.available()]; System.out.println("read="+is.available()); is.read(bs1); String encode = bs.encode(bs1); System.out.println(encode); is.close(); os=new FileOutputStream(file); os.write(encode.getBytes()); os.close(); System.out.println("=====================decoding========================"); BASE64Decoder decoder=new BASE64Decoder(); byte[] decodeBuffer = decoder.decodeBuffer(new FileInputStream(file)); String s=new String(decodeBuffer); System.out.println(s); File f=new File("C:\\Users\\Shashika\\Desktop\\enc\\enc0000.html"); OutputStream os1=new FileOutputStream(f); os1.write(decodeBuffer); os1.flush(); os1.close(); // for (byte b : bs1) { // System.out.println("byte="+b); // } } catch (Exception ex) { Logger.getLogger(Encrypt.class.getName()).log(Level.SEVERE, null, ex); } break; } // bs.encode(); catch (FileNotFoundException ex) { Logger.getLogger(Encrypt.class.getName()).log(Level.SEVERE, null, ex); } finally { try { is.close(); } catch (IOException ex) { Logger.getLogger(Encrypt.class.getName()).log(Level.SEVERE, null, ex); } } } // bs.encode(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)