学习一下知识吧,好久没有写博客了。如果他总为别人撑伞,你又何苦非为他等在雨中。

学习的知识内容

一、关于base64的图片问题

byte[] decode = Base64.base64ToByteArray(string);
String strings = new String(decode);
IOUtils.write(strings, new FileOutputStream("D:/huhx1.png")); // we can't open this file
IOUtils.write(decode, new FileOutputStream("D:/huhx2.png")); // 正常显示

感觉在浏览器上,base64的前缀比较宽松。只要data:.....;base64。....中间的内容可以随意,具体情况也不是很明朗。以下是可以显示图片的。

上述的src的内容是图片的二进制流经过base编码的,想要保存图片的话。需要对内容进行base的解码操作,再将解码之后的字节保存为图片。

关于图片base64可以参考博客:http://www.cnblogs.com/coco1s/p/4375774.html

二、关于classLoader的一些继承关系

public void classLoader_1() {
ClassLoader classLoader = getClass().getClassLoader();
System.out.println(classLoader); // sun.misc.Launcher$AppClassLoader@3b05c7e1 ClassLoader parent = classLoader.getParent();
System.out.println(parent); // sun.misc.Launcher$ExtClassLoader@7885a30c ClassLoader parent1 = parent.getParent();
System.out.println(parent1); // null
}

三、关于new File的路径问题

@Test
public void relativePath_1() {
File file = new File("path/huhx.png"); // G:\Java\JavaEE\Program\2016-05-15\SpringLearn\huhx-test\path\huhx.png
System.out.println(file.getAbsolutePath());
} @Test
public void absolutePath_1() {
File file = new File("/path/huhx.png"); // G:\path\huhx.png
System.out.println(file.getAbsolutePath());
}

四、关于classLoader的getResource方法

// programPath = G:/Java/JavaEE/Program/2016-05-15/SpringLearn/huhx-test
public void classStreamPath_1() {
System.out.println(Thread.currentThread().getContextClassLoader().getResource("")); // file:/programPath/target/test-classes/
System.out.println(getClass().getClassLoader().getResource("")); // file:/programPath/target/test-classes/
System.out.println(ClassLoader.getSystemResource("")); // file:/programPath/target/test-classes/
System.out.println(getClass().getResource("")); // file:/programPath/target/test-classes/com/linux/huhx/filepath/
System.out.println(getClass().getResource("/")); // file:/programPath/target/test-classes/
System.out.println(new File("/").getAbsolutePath()); // G:\
System.out.println(System.getProperty("user.dir")); // G:\Java\JavaEE\Program\2016-05-15\SpringLearn\huhx-test
}

五、关于编码的一些知识

public void charsetTest_1() {
String string = "刘玲";
String str = new String(string.getBytes()); // 默认的是utf-8的
System.out.println(str); // 刘玲 Charset charset = Charset.forName("gbk");
ByteBuffer byteBuffer = charset.encode("刘玲"); byte[] buffers = byteBuffer.array();
System.out.println(new String(buffers)); // ����� CharBuffer charBuffer = charset.decode(byteBuffer); // 刘玲
System.out.println(charBuffer); try {
System.out.println(new String(buffers, "gbk")); // 刘玲
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}

六、嵌套目录的创建和删除

public void fileTest_1() {
File file = new File("D:/liuling/liuling/huhx.txt");
if (!file.exists()) {
// 现在的目录D:/liuling/liuling/huhx.txt,注意这里的huhx.txt是一个目录名。
System.out.println(file.mkdirs()); // true
}
File deletefile = new File("D:/liuling");
System.out.println(deletefile.delete()); // false
// huhx.txt目录被删除了
System.out.println(file.delete()); // true
}

file.mkdir();是创建一级的子目录, mkdirs()是可以创建多级的嵌套子目录的。

七、关于java中的foreach的null问题

public void forEachTest() {
String[] strings = null;
for (String string : strings) { // java.lang.NullPointerException System.out.println(string);
}
List<String> lists = null;
for (String list : lists) { // // java.lang.NullPointerException
System.out.println(list);
} List<String> list2s = new ArrayList<>();
for (String list : list2s) {
System.out.println(list); // 没有任何的打印
}
}

ps:上述的文件不能直接运行的,因为异常的存在,后面的流程指定是不能执行的。

八、java中的import static使用

当在java中如果使用类的static方法和static变量时,可以import static该方法或者是变量。在代码中可以不用className.变量,而可以直接使用。下面是一个例子。

import static com.linux.huhx.utils.RegrexUtils.*;

String requestData = messageFormat(action, arrays[0], arrays[1]);

而在RegrexUtils中的messageFormat是一个static方法定义如下:

public static String messageFormat(String string, String... replace) {
if (ArrayUtils.isEmpty(replace)) {
return string;
}
for (int i = 0; i < replace.length; i++) {
string = string.replace("{" + i + "}", replace[i]);
}
return string;
}

这里本来是想使用MessageFormat.format方法的,但是在解析某些字符串时,出现了问题。

九、关于Servlet中的请求对象的一些路径的方法

访问的url:http://localhost:8080/ListenerTest1/servlet/FirstServlet,ListenerTest1是项目名。

String contextPath = request.getContextPath();
String servletPath = request.getServletPath();
String realPath = request.getServletContext().getRealPath("/");

运行的结果如下:

/ListenerTest1
/servlet/FirstServlet
J:\project\web\apache-tomcat-7.0.-windows-x64\apache-tomcat-7.0.\webapps\ListenerTest1\

友情链接

日记整理---->2017-05-14的更多相关文章

  1. Gitlab一键端的安装汉化及问题解决(2017/12/14目前版本为10.2.4)

    Gitlab的安装汉化及问题解决 一.前言 Gitlab需要安装的包太TM多了,源码安装能愁死个人,一直出错,后来发现几行命令就装的真是遇到的新大陆一样... ... 装完之后感觉太简单,加了汉化补丁 ...

  2. java selenium启动火狐浏览器报错:Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: VISTA Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:14.666Z

    Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: VISTA Build in ...

  3. 2021.05.14 tarjan

    2021.05.14 tarjan 标准版tarjan 这里使用数组来模拟栈 void tarjan(int x){ ++ind; dfn[x]=low[x]=ind; stacki[++top]=x ...

  4. 2017.10.14 Java的流程控制语句switch&&随机点名器

    今日内容介绍 1.流程控制语句switch 2.数组 3.随机点名器案例 ###01switch语句解构     * A:switch语句解构       * a:switch只能针对某个表达式的值作 ...

  5. informatica 学习日记整理

    1. INFORMATICA CLIENT的使用 1.1 Repository Manager 的使用 1.1.1 创建Repository. 前提: a.在ODBC数据源管理器中新建一个数据源连接至 ...

  6. AC日记——整理药名 openjudge 1.7 15

    15:整理药名 总时间限制:  1000ms 内存限制:  65536kB 描述 医生在书写药品名的时候经常不注意大小写,格式比较混乱.现要求你写一个程序将医生书写混乱的药品名整理成统一规范的格式,即 ...

  7. 寻找大学目标及行动步骤——记ITAEM团队第二期宣讲会(2014.05.14)

    ·昨晚8:00-9:40.在 钟海楼03029 ,进行了ITAEM团队第二期宣讲会(第一期见第一期宣讲会总结).来參加的主要是大一学生.以信院为主.也有法学院.文学院的同学. 在宣讲会中,大家都比較积 ...

  8. 团队作业4——第一次项目冲刺(Alpha版本)2017.11.14

    第一次会议:2017-11-14 额--这几天比较忙,忘记上传了,今天补上 先上个图,O(∩_∩)O哈哈: 会议主要内容: 1. 讨论整体框架 2. 个人具体分工 3. 代码统一 具体分工: 成员 计 ...

  9. 日记整理---->2016-11-01

    这里我们整理一下项目的流程,一般来说做一个模块之前.会有需求文档.页面原型和接口文档. 一. js获取radio的值 页面的html代码: <ul class="list-group& ...

  10. OpenSpiel 随笔 05.14

    ------------恢复内容开始------------ 这两天年总算把自己的游戏写完了,也通过了所有的测试. 我将自己的代码上传到了我的github上, 地址是 https://github.c ...

随机推荐

  1. Wings 3D

    Wings 3D 编辑 Wings 3D 是一个开源的三维计算机图形软件.使用翼边数据库.注重于多边形建模,构思取与 Izware 的 Nendo 和 Mirai.支持多种操作系统,包括 Linux. ...

  2. EJB与JPA的关系

    转自:http://www.cnblogs.com/o-andy-o/archive/2012/04/17/2453537.html JPA是基于Java持久化的解决方案,主要是为了解决ORM框架的差 ...

  3. Single Pattern(单例模式)

    单例模式是一种常用的软件设计模式.通过单例模式可以保证系统中一个类只有一个实例而且该实例易于外界访问,从而方便对实例个数的控制并节约系统资源.如果希望在系统中某个类的实例只能存在一个,单例模式是最好的 ...

  4. windows下更改鼠标滚轮方向

    本来鼠标滚轮的方向无所谓“正确”与否(win下和mac下方向相反),只要习惯即可.但从win下切换到mac后,本来是想把鼠标方向调成跟win下一致,结果这么一反转,连多指手势的“左右”都反了,苹果,算 ...

  5. BarTender软件中GS1-128条码如何制作?

    GS1-128条码是UCC/EAN-128条码的新名字,它只是Code 128的一个特殊子集.GS1-128条码是EAN·UCC系统中唯一可用于表示附加信息的条码,可广泛用于非零售贸易项目.物流单元. ...

  6. Linux远程管理之SVN,VNC

    一.远程管理的基本概念 首先我们来初略的讲讲远程管理的一些基本概念.对于我们使用的计算机来说,如果是个人计算机,就没有远程管理这一概念了,想用的时候开机就能使用,而对于我们的服务器来说,就不同了,对于 ...

  7. python中,获取字符串的长度

    说明: 与其他的语言一样,有时候需要查看或者说计算字符串的长度.在此记录下python中通过哪个函数实现. 操作过程: 1.通过len()函数返回字符串的长度 >>> text='p ...

  8. python中,如有个非常长的字符串,在写的时候如何将其分隔

    说明: 比如,有个长字符串,Put several strings within parentheses to have them joined together.但是我在写脚本的时候, 想要放在多行 ...

  9. kendo-ui的MVVM模式

    摘要: MVVM(Model View ViewModel)是一种帮助开发者将数据从模型分离的设计模式.MVVM的ViewModel负责将数据对象从模型中分离出来,通过这种方式数据就很容易控制数据如何 ...

  10. redis sentinels哨兵集群环境配置

    # Redis configuration file example. # # Note that in order to read the configuration file, Redis mus ...