zoukankan      html  css  js  c++  java
  • java 字符串转Base64

    场景一:

    String base64encodedString = Base64.getEncoder().encodeToString("123".getBytes("utf-8"));
    	         System.out.println("Base64 编码字符串 (基本) :" + base64encodedString);
    

    场景二:

    String str = "123";
    byte[] datas = str.getBytes();
    bs.write(datas,0,datas.length);
    bs.flush();
    byte[] dest = bs.toByteArray();
    String s0 =Base64.getEncoder().encodeToString((dest)); 

    场景三:

    ByteArrayOutputStream bos = null;
    FileInputStream fs = null;
     try
     {
    	 bos = new ByteArrayOutputStream();
    	  fs = new FileInputStream("D:\1.txt");
    	  int len;
    	  while((len = fs.read()) != -1)
    	  {
    	           bos.write(len);
    	   }
    	   //转换成byte字符数组
    	   byte[] array = bos.toByteArray();
    	   String s1 =Base64.getEncoder().encodeToString((bos.toByteArray()));
    	   // 指定解码的字符集utf-8
    	    System.out.println(new String(array, "utf-8"));
    	     fs.close();
    }
    catch(IOException e)
    {}
    finally
    {
    	bos.close();
    	 fs.close();
    }
    

      

      

    1、建了一个小群:616945527(软件), 欢迎大家加入,加群口令abc123,硬件嵌入式开发者推荐75764412(单片机)。
    闲置域名www.nsxz.com出售(等宽等高字符四字域名,可组合多种有意义词语)。
  • 相关阅读:
    thinkphp--标签库
    thinkphp中的参数绑定
    thinkphp3.2.3子查询中遇到的错误
    开篇马克
    BST树、B-树、B+树、B*树
    linux shell编程之变量和bash配置文件(第一篇)
    linux awk进阶篇
    linux awk(gawk)
    linux sed命令
    linux basic
  • 原文地址:https://www.cnblogs.com/zhaogaojian/p/14605256.html
Copyright © 2011-2022 走看看