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 这些博客具有以下特点: 文章的可读性和有独创 ...
随机推荐
- 17.1.1.7 Setting Up Replication with New Master and Slaves 设置复制对于新的Master和Slaves:
17.1.1.7 Setting Up Replication with New Master and Slaves 设置复制对于新的Master和Slaves: 最简单和最直接的方法是设置复制用于使 ...
- ZooKeeper - Perl bindings for Apache ZooKeeper Perl绑定用于 Apache ZooKeeper
ZooKeeper - Perl bindings for Apache ZooKeeper Perl绑定用于 Apache ZooKeeper 监控 master/slave 需要使用zk的临时节点 ...
- datanode启动后,在web50070port发现不到datanode节点(能力工场)
直接上问题:这两天为了试验,安装了两套集群: (1)32位hadoop1集群(5个节点); (2)64位hadoop2集群(6个节点) 两个集群中都遇到过这种问题:在namenode正常启动hadoo ...
- 关于DataGridViewComboBoxCell修改后提交数据源
最近在项目遇到一个功能实现.是在DataGridView中DataGridViewComboboxColumn列绑定数据源, DisplayMember为数据表的Name列,ValueMember是数 ...
- UNIX环境高级编程——TCP/IP网络编程
常用网络信息检索函数 gethostname() getppername() getsockname() gethostbyname() gethostbyaddr() getprotobyname( ...
- CF#213DIV2:B The Fibonacci Segment
You have array a1, a2, ..., an. Segment [l, r] (1 ≤ l ≤ r ≤ n) is good if ai = ai - 1 + ai - 2, for ...
- hibernate 一对多映射
package com.entity.onetomany; import java.util.ArrayList; import java.util.List; import javax.persis ...
- FireMonkey下的异形窗体拖动(句柄转换)
DelphiXE2 Firemoney FMX 的窗体不只是为windows的, 所以很多功能都没有了. 最常见的就是拖拽了 先看 VCL时代 一个经典拖动代码 ReleaseCapture(); S ...
- Qt持久性对象进行序列化(同时比较了MFC与Java的方法)
Mfc和Java中自定义类的对象都可以对其进行持久性保存,Qt持久性对象进行序列化当然也是必不可少的.不过这个问题还真困扰了我很长时间……Mfc通过重写虚函数Serialize().Java则是所属的 ...
- CCIE路由实验(6) -- 组播Multicasting
1.组播IGMP的各种情况2.PIM Dense-Mode3.PIM Sparse-Mode4.PIM双向树和SSM5.动态RP之auto-rp6.动态RP之BSR7.Anycast RP8.域间组播 ...