Java 学习
benjiazhen
相信技术可以改变命运,改变世界
展开
-
Class.getResource,ClassLoader.getResource 和 System.getProperty("user.dir")的对比
本文将从两个方面对比,一个是在工程中运行,一个是打成jar包运行1.在工程中运行2.打成jar包运行 可运行jar包 作为第三方jar包,供其他工程调用总结:1.class.getResource(String path) path不以’/'开头时,默认是从此类所在的包下取资源; path原创 2016-11-22 15:43:52 · 743 阅读 · 0 评论 -
javaweb工程无需修改配置文件多环境热加载部署,
现在碰到这样的问题,有一个web工程打成war包后,需要在开发环境,测试环境,生产环境部署,每次都需要提前修改对应环境的配置信息,比如,数据库地址,zookeeper集群地址等,非常的不方便,并且容易忘记并出错,为了能够一次打包,无需修改配置文件直接多环境热加载部署,提出并实践了以下解决方案:1.war包改成rpm打包。传统的war包放在tomcat的webapps目录下,会全量覆盖以前的原创 2016-11-28 14:22:49 · 1843 阅读 · 0 评论 -
JVM性能优化常用命令
1.jmap-dump:format=b,file=logic_heap.hprof pid这个命令,dump出内存的映像状态文件,再使用MemoryAnalyzer这个工具分析,可以查看哪些类可能存在内存泄漏2.jstack pid此命令能得到运行java程序的java stack和native stack的信息。可以轻松得知当前线程的运行情况,这个和thread dump原创 2016-11-18 10:25:03 · 415 阅读 · 0 评论 -
文件上传获取文件的contentType
public static String getMimeType(String filePath) throws Exception{if(filePath == null && filePath.equals("")){tjrows new Exception("filePath is null or empty");}Path tmpPath = Paths.get原创 2016-11-18 15:09:01 · 5129 阅读 · 0 评论 -
java 字符串首字母小写转大写
public static String convertToCapitalLetter(String seq,int index){if(index >= seq.length()){throw new IndexOutOfBoundsException(); }char[] chars = seq.toCharArray();chars[index] -=32;原创 2016-11-25 10:12:48 · 788 阅读 · 0 评论 -
常用正则表达式(持续补充
验证IP集群:(((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?):[\\d]+[,]?)+原创 2017-01-14 09:51:11 · 437 阅读 · 0 评论 -
欢迎使用CSDN-markdown编辑器
使用Java获取本地IPpublic static String getNativeIP() throws UnknownHostException { InetAddress inetAddress = InetAddress.getLocalHost(); if(null != inetAddress && !inetAddress.isLoopbackA原创 2017-02-23 14:06:07 · 283 阅读 · 0 评论