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. 我也来说说C#中的异步:async/await

    序 最近看了一些园友们写的有关于异步的文章,受益匪浅,写这篇文章的目的是想把自己之前看到的文章做一个总结,同时也希望通过更加通俗易懂的语言让大家了解"异步"编程. 1:什么是异步 ...

  2. 练习 jquery+Ajax+Json 绑定数据 分类: asp.net 练习 jquery+Ajax+Json 绑定数据 分类: asp.net

    练习 jquery+Ajax+Json 绑定数据

  3. bootstrap base css 基本css

    Headings All HTML headings, <h1> through <h6> are available. h1. Heading 1 h2. Heading 2 ...

  4. Automake创建项目

    autoconf和automake可以方便的构建linux下项目,一个简单的automake项目实例,麻雀虽小五脏俱全,以后无外乎在这基础上扩展相应的宏完善而已. .首先建立项目目录树 )创建目录树 ...

  5. 用php 把数组中偶数,选择出来

    我有这种一个小算法,把数组中的全部的偶数或技术分别选择出来.非常多人可能,会循环这个数组,而我恰恰不循环数组就能做到这一点.代码例如以下. function odd($var) { // return ...

  6. 下载并在Eclipse中关联Android源代码

    大家都知道文档写的好当然让人非常舒服,可是有时候文档再好也不如直接看源代码来的直接,既然Android是开源的,为什么不在eclipse里直接看它的源代码呢? 1.下载源代码 这部分网上有大量的资料, ...

  7. TortoiseSVN (一) - 疑难操作

    引用: http://blog.sina.com.cn/s/blog_74c22b210101cy3s.html   一.由于Unity打包过程需要耗费很长的时间,在测试过程中如果只需测某几种功能,则 ...

  8. Python 第二篇:python字符串、列表和字典的基本操作方法

    本文基于python 3.5.1 python常见的数据类型有字串.列表.元组.字典等,本文将详细介绍每一种数据类型的操作方法. 一:str字串的操作方法: 1.capitalize()-->  ...

  9. Python3 正则表达式特殊符号及用法(详细列表) http://bbs.fishc.com/thread-57691-1-1.html (出处: 鱼C论坛)

    http://bbs.fishc.com/thread-57691-1-1.html 留待查询用

  10. 只启动一个zookeeper配置 server1只需要配置一个

    [root@wx03 conf]# cat zoo.cfg # The number of milliseconds of each tick tickTime=2000 # The number o ...