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)的更多相关文章

  1. How to Create a Java Concurrent Program

    In this Document   Goal   Solution   Overview   Steps in writing Java Concurrent Program   Template ...

  2. 编写一个应用程序,利用数组或者集合, 求出"HELLO",“JAVA”,“PROGRAM”,“EXCEPTION”四个字符串的平均长度以及字符出现重复次数最多的字符串。

    public class Number { public static void main(String[] args) { String[] arr = { "HELLO", & ...

  3. tomcat Failed creating java C:\Program Files\Java\jre6\bin\client\jvm.dll %1 不是有效的 Win32 应用程序。

    jdk版本搞的鬼 请下载64位的jdkj进行安装

  4. OAF_开发系列27_实现OAF中Java类型并发程式开发调用XML Publisher(案例)

    20150814 Created By BaoXinjian

  5. OAF_开发系列25_实现OAF中Java类型并发程式开发oracle.apps.fnd.cp.request(概念)

    20150719 Created By BaoXinjian

  6. 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 ...

  7. 在Service Fabric上部署Java应用,体验一把微服务的自动切换

    虽然Service Fabric的Java支持版本还没有正式发布,但是Service Fabric本身的服务管理.部署.升级等功能是非常好用的,那么Java的开发者可以如何利用上Service Fab ...

  8. java的JVM机制

    1.jre:java运行环境 提供一个JVM和一些基础类库.2.只安装jre以后,机器就具备了运行java程序的条件.但是不具备开发java程序的条件.安装JDK以后,在c:/program file ...

  9. 转发——推荐一些国外高质量Java开发者的博客

    学习Java很不错的一篇博客,总结了很详尽的Java开发者博客. http://www.admin10000.com/document/3373.html 这些博客具有以下特点: 文章的可读性和有独创 ...

随机推荐

  1. django-debug-toolbar

    一:安装django-debug-toolbar. 二:在settings里的MIDDLEWARE_CLASSES加入'debug_toolbar.middleware.DebugToolbarMid ...

  2. mul16

    设计思想:乘法运算本身就可以看做是一个移位相加的过程               1 1 0 1 0     = 26*              1 0 1 1 1    = 23          ...

  3. Qt中文件操作遇到的(变量,容器,结构体)

    咳咳!总结了一下我在使用QT文件操作时所用到的,再接再厉!再接再厉!! 1.保存到文件: QFile file("test.txt"); if (!file.open(QIODev ...

  4. Python 2.7 学习笔记 模块和包

    我们来考虑下如下几种场景: 1.编写一个python程序,如果程序比较简单,则可以把代码放到一个python文件中.但如果程序功能比较多,可能需要多个python文件来组织源代码.而这些文件之间的代码 ...

  5. springmvc+mybatis+redis(转)

    最近在学习redis的使用方法,它的本地使用方法比较简单,只需要先启动Redis服务器,然后运行测试代码即可.但是现在我想要在网站上访问数据库的时候采用Redis缓存,问题就出来了.要么是缓存直接失效 ...

  6. get get_children方法

    get 方法: [root@wx03 zook]# cat a4.pl use ZooKeeper; use AnyEvent; use AE; use Data::Dumper; my $zk = ...

  7. FLUSH TABLES WITH READ LOCK 锁全局

    [root@wx03 ~]# cat a3.sh mysql -uroot -p1234567<<eof use scan; FLUSH TABLES WITH READ LOCK; sy ...

  8. Google Map Android api V2 中使用MapView遇到CameraUpdateFactory is not initialized!的解决办法

    先说一下 Map V2 API Key 的问题吧: 在打包APP时需要自己生成一个XXX.keystore 用这个密室库生成的SHA1去申请的key 作为AndroidManifest.xml 中的K ...

  9. Mac OSX的开机启动配置

    Login Items Mac OSX的当前用户成功登录后启动的程序,该类别的启动项配置文件存放在~/Library/Preferences/com.apple.loginitems.plist,所以 ...

  10. FireMonkey下的异形窗体拖动(句柄转换)

    DelphiXE2 Firemoney FMX 的窗体不只是为windows的, 所以很多功能都没有了. 最常见的就是拖拽了 先看 VCL时代 一个经典拖动代码 ReleaseCapture(); S ...