Java tutorial
/* * SubCherry - Cherry Picking with Trac and Subversion * Copyright (C) 2014 Bernhard Haumacher and others * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package base64; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import org.apache.commons.codec.binary.Base64; /** * Reads a string from standard input and encodes it base64. * * @version $Revision$ $Author$ $Date$ */ public class EncodeBase64 { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter string to encode (input is not escaped):"); String originalString = reader.readLine(); String encodedBase64String = Base64.encodeBase64String(originalString.getBytes()); System.out.println("Your encoded Base64 string :"); System.out.println(encodedBase64String); } }