使用java脚本编码和解码html页面(使用base64) [英] encode and decode a html page using java script (used base64)

查看:92
本文介绍了使用java脚本编码和解码html页面(使用base64)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用Java做了这个我想用javascript解码html页面样本会很好

i have done this with Java i want to decode the html pages using javascript a sample will be good

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();

    }
}

推荐答案

这是使用JavaScript的Base64编码器和解码器 [ ^ ]





您可以读取文件JS [ ^ ]并执行使用读取数据的操作,但您无法使用JS写入本地磁盘(除了Google Gears等少数例外)





Best ,

H
Here is a Base64 Encoder and Decoder with JavaScript[^]


You can read files in JS [^]and perform actions using the read data, but you cannot write to the local disk using JS (with a few exceptions like Google Gears)


Best,
H


访问这里



http://www.hashemian.com/tools/base64-encode-decode.php [ ^ ]


这篇关于使用java脚本编码和解码html页面(使用base64)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆