JAVA Useful Program(1)
public static void main(String[] args){
//字符串有整型的相互转换
String str=String.valueOf(123);
int i=Integer.parseInt(str);
System.out.println(i);
//向文件末尾添加内容
BufferedWriter out = null;
try{
out = new BufferedWriter(new FileWriter("c://logs//log.out", true));
out.write("aString");
}catch(IOException ex){
System.out.println(ex.getMessage());
}finally{
if(out!=null){
try {
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
//得到当前方法的名字
String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
System.out.println(methodName);
//转字符串到日期
SimpleDateFormat format = new SimpleDateFormat( "dd.MM.yyyy" );
try {
Date date = format.parse("01.01.2013");
System.out.println(date);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//把 Java util.Date 转成 sql.Date
java.util.Date utilDate = new java.util.Date();
java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
System.out.println(sqlDate);
//使用NIO进行快速的文件拷贝
File f1=new File("c://logs//log.out");
File f2=new File("c://logs//log1.out");
FileChannel inChannel=null;
FileChannel outChannel=null;
try {
inChannel = new FileInputStream(f1).getChannel();
outChannel = new FileOutputStream(f2).getChannel();
try{
int maxCount = (64 * 1024 * 1024) - (32 * 1024);
long size = inChannel.size();
long position = 0;
while ( position < size ){
position += inChannel.transferTo( position, maxCount, outChannel );
}
}catch(FileNotFoundException ex){
ex.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(inChannel!=null){
try {
inChannel.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(outChannel!=null){
try {
outChannel.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
Output:
123
main
Tue Jan 01 00:00:00 CST 2013
2013-06-17
JAVA Useful Program(1)的更多相关文章
- How to Create a Java Concurrent Program
In this Document Goal Solution Overview Steps in writing Java Concurrent Program Template ...
- 编写一个应用程序,利用数组或者集合, 求出"HELLO",“JAVA”,“PROGRAM”,“EXCEPTION”四个字符串的平均长度以及字符出现重复次数最多的字符串。
public class Number { public static void main(String[] args) { String[] arr = { "HELLO", & ...
- tomcat Failed creating java C:\Program Files\Java\jre6\bin\client\jvm.dll %1 不是有效的 Win32 应用程序。
jdk版本搞的鬼 请下载64位的jdkj进行安装
- OAF_开发系列27_实现OAF中Java类型并发程式开发调用XML Publisher(案例)
20150814 Created By BaoXinjian
- OAF_开发系列25_实现OAF中Java类型并发程式开发oracle.apps.fnd.cp.request(概念)
20150719 Created By BaoXinjian
- How to deploy JAVA Application on Azure Service Fabric
At this moment, Azure Service Fabric does not support JAVA application natively (but it's on the sup ...
- 在Service Fabric上部署Java应用,体验一把微服务的自动切换
虽然Service Fabric的Java支持版本还没有正式发布,但是Service Fabric本身的服务管理.部署.升级等功能是非常好用的,那么Java的开发者可以如何利用上Service Fab ...
- java的JVM机制
1.jre:java运行环境 提供一个JVM和一些基础类库.2.只安装jre以后,机器就具备了运行java程序的条件.但是不具备开发java程序的条件.安装JDK以后,在c:/program file ...
- 转发——推荐一些国外高质量Java开发者的博客
学习Java很不错的一篇博客,总结了很详尽的Java开发者博客. http://www.admin10000.com/document/3373.html 这些博客具有以下特点: 文章的可读性和有独创 ...
随机推荐
- select()函数详解
Select在Socket编程中还是比较重要的,可是对于初学Socket的人来说都不太爱用Select写程序,他们只是 习惯写诸如connect. accept.recv或recvfrom这样的阻塞程 ...
- Qt对话框_模态/非模态
对话框在Qt GUI应用程序中有着广泛的用途,对话框有模态.非模态两种情况. 对于参数选择的对话框,一般用模态对话框:对于显示或查看某些内容的对话框,一般用非模态对话框. 对话框类QDialog,官方 ...
- Spirng+SpringMVC+Maven+Mybatis+MySQL项目搭建(转)
这篇文章主要讲解使用eclipse对Spirng+SpringMVC+Maven+Mybatis+MySQL项目搭建过程,包括里面步骤和里面的配置文件如何配置等等都会详细说明. 如果还没有搭建好环境( ...
- Page的生命周期及相关事件苛
(1)请求页面:页请求发生在页生命周期开始之前. (2)开始:在开始阶段,将设置页属性,如Request和Response.在此阶段,页还将确定请求是回发请求还是新请求,并设置IsPostBack属性 ...
- [置顶] HMM Tutorial 隐马尔科夫模型
有一个月没有写博客了,这一个月系统的学习了HMM model. 上周周五做了个report 感觉还好. 所以把Slide贴上来.
- Android进程内存上限
Android应用程序都是在自己单独的进程中运行.Android为不同类型的进程分配了不同的内存使用上限,如果应用进程使用的内存超过了这个上限,则会抛出Out Of Memory异常,接着进程也被ki ...
- UNIX网络编程 卷2:进程间通信
这篇是计算机类的优质预售推荐>>>><UNIX网络编程 卷2:进程间通信(第2版)> UNIX和网络专家W. Richard Stevens的传世之作 编辑推荐 两 ...
- javascript每日一练(十)——运动二:缓冲运动
一.缓冲运动 实现原理:(目标距离-当前距离) / 基数 = 速度(运动距离越大速度越小,运动距离和速度成反比) (500 - oDiv.offsetLeft) / 7 = iSpeed; 需要注意: ...
- javascript每日一练(六)——事件一
一.event对象 var oEvent = ev || event;//获取事件对象 oEvent.clientX oEvent.clientY//获取鼠标坐标 oEvent.cancelBubbl ...
- Wince下实现ImageButton
我们在winform中给按钮设置个背景图片超级简单,是不?可是在wince下面就没那么简单了,下面我来介绍一种方式来实现ImageButton. 实现思路是重新写一个usercontrol就ok.具体 ...