整理用Java实现数字转化成字符串左边自动补零方法
Java 中给数字左边补0 (1)方法一
import java.text.NumberFormat; public class NumberFormatTest { public static void main(String[] args) {
//待测试数据
int i = 1;
//得到一个NumberFormat的实例
NumberFormat nf = NumberFormat.getInstance();
//设置是否使用分组
nf.setGroupingUsed(false);
//设置最大整数位数
nf.setMaximumIntegerDigits(4);
//设置最小整数位数
nf.setMinimumIntegerDigits(4);
//输出测试语句
System.out.println(nf.format(i));
}
} 来源:http://blog.csdn.net/xiaohunzhang/archive/2008/08/07/2782592.aspx (2)方法二(个人以为该方法简单有效,但经试验似乎String.format()函数有问题) public class TestStringFormat {
public static void main(String[] args) {
int youNumber = 1;
// 0 代表前面补充0
// 4 代表长度为4
// d 代表参数为正数型
String str = String.format("%04d", youNumber);
System.out.println(str); // 0001
}
}
来源:http://liuwei1981.javaeye.c
相关文档:
1、 Web.xml
1) 配置hibernate
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dbConnectionContext.xml /WEB-INF/serviceContext.xml</param-value> ......
import java.net.URL;
import java.net.URLDecoder;
public class PathUtil
{
/**
* Get the env of windir, such as "C:\WINDOWS".
* @return the env of windir value.
*/
public static String getWindir(){
return System.getenv("windir");
}
......
这几天测试blob获取和存储的时候,被卡了很久,最后才发现是占用了关键字导致无法获取结果,血的教训啊.
以后起名字要用最恶心的,不要用最方便的了.闲话少说,java的hashmap是不能直接存储到数据库中的.
本地数据库为mysql,里面有blob的类型可供使用.方法也很简单,上代码
数据库建表
CREATE TABLE `test` (
`id` ......