⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example.java

📁 java base64
💻 JAVA
字号:
package com.mindprod.base64;

/**
 * Example code to test and use Base64 encode and decode. to run: java.exe com.mindprod.base64.Example
 *
 * @author Roedy Green, Canadian Mind Products
 * @version 1.7, 2007-03-15 Created with IntelliJ IDEA.
 */
public final class Example
    {
    // --------------------------- main() method ---------------------------

    public static void main( String arg[] ) throws java.io.UnsupportedEncodingException
        {
        /* encode and decode a string */
        String originalString = "Hello world";
        byte[] sendBytes = originalString.getBytes( "8859_1"/* encoding */ );
        Base64 base64 = new Base64();
        base64.setLineLength( 72 );
        String encoded = base64.encode( sendBytes );
        byte[] reconstitutedBytes = base64.decode( encoded );
        String reconstitutedString =
                new String( reconstitutedBytes, "8859_1"/* encoding */ );

        /* display all intermediate results in encode decode process */
        // in JDK 1.5+ could import static System.out;
        System.out.println( "originalString:" + " " + originalString );
        System.out.print( "sendBytes:" );
        // in JDK 1.5+ could use for each
        for ( int i = 0; i < sendBytes.length; i++ )
            {
            byte b = sendBytes[ i ];
            System.out.print( " " + Integer.toHexString( b ) );
            }
        System.out.println();
        System.out.println( "encoded:" + encoded + "\n" );
        System.out.print( "reconstitutedBytes:" );
        for ( int i = 0; i < reconstitutedBytes.length; i++ )
            {
            byte b = reconstitutedBytes[ i ];
            System.out.print( " " + Integer.toHexString( b ) );
            }
        System.out.println();
        System.out
                .println( "reconstitutedString:" + " " + reconstitutedString );
        }
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -