20110623

将数据库里的BLOB值查出来,生成文件:
byte[] byteArray = rs.getBytes(1);
File file = new File(...);
file.createNewFile();
OutputStream out = new FileOutputStream(file);
out.write(byteArray);
out.close();

====================
String.format(...)方法
String str= String.format("%02d", 5);
输出为“05”,左面不足补零
====================
压缩文件:
public void compressFiles(List<File> list, File zipFile) throws Exception {
BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream(zipFile));
ZipOutputStream zos = new ZipOutputStream(bos);
BufferedInputStream bis = null;
try {
for (File file : list) {
bis = new BufferedInputStream(new FileInputStream(file));
zos.putNextEntry(new ZipEntry(file.getName()));
int len;
while ((len = bis.read()) > 0) {
zos.write(len);
}
zos.closeEntry();
bis.close();
}
} catch (IOException e) {
throw new Exception("Compress file failed!");
} finally {
try {
if (bis != null) {
bis.close();
}
if (zos != null) {
zos.close();
}
} catch (IOException e) {
// do some log for the I/O not correct close.
}
}
}
==================
JDBC 存储Blob
File fileIn = new File(...);
bodyIn = new FileInputStream(fileIn);
ps.setBinaryStream(3, bodyIn, (int) fileIn.length());
=================
shell 运行java:
#!/bin/sh
JAVA_HOME=/opt/jdk1.6.0_16
test_home=/a/b
lib=$test_home/lib
cp=$test_home
cd $lib
for jar in *.jar
do
cp=$cp:$lib/$jar
done
echo $cp
cd $test_home
#need three parameters to java program
$JAVA_HOME/bin/java -cp $cp a.b.Runner $1 $2 $3

============
public class TryFinnally {
public static void main(String[] args) {
int i=0;
try{
++i;
System.out.println("In the try,the i value is :"+i);
throw new RuntimeException();
}catch(Exception e){
++i;
System.out.println("In the catch,the i value is :"+i);
}finally{
++i;
System.out.println("In the finally,the i value is :"+i);
}
++i;
System.out.println("after the finally,the i value is :"+i);


}
}
The result is:
In the try,the i value is :1
In the catch,the i value is :2
In the finally,the i value is :3
after the finally,the i value is :4
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值