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. bresenham算法的FPGA的实现1

    接着上一篇的 计算实现给出屏幕上任意两个点,求出这两个点之间直线上的所有的点.http://www.cnblogs.com/sepeng/p/4042464.html 这种直接算法的确是被鄙视了 强大 ...

  2. PLSQL Developer使用技巧整理(转)

    一.工具-首选项-用户界面-编辑器-其它-显示行号二.工具-首选项-窗口类型-SQL窗口-显示隔号(行号) 在使用PL/SQL Developer对Procedure进行Debug时,突然发现无法Se ...

  3. php下载远程图片方法总结(curl手动解析header)curl跳转问题解决

    常用方法一般有:. file_get_contents file_put_contents readfile($file) //效率很高. 一般代码: /** * 抓取远程图片 * * @param ...

  4. android JB2连拍降速原理介绍

    1.HAL层 (1)alps\mediatek\platform\mt6589\hardware\camera\core\camshot\MultiShot\MultiShot.cpp sleep实现 ...

  5. hdu 4975 A simple Gaussian elimination problem.(网络流,推断矩阵是否存在)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4975 Problem Description Dragon is studying math. One ...

  6. VMware Workstation 9.0 安装苹果Mac OS X10.9系统

    摘自:http://www.wuwenhui.cn/3133.html 一.安装所需要的软件: 1.VMware Workstation 9.0 点击下载 2.unlock-all-v110.zip  ...

  7. asp.net 通过 Handler 导出数据至excel (让用户下载)

    效果图: 代码: Export2Excel.ashx <%@ WebHandler Language="C#" CodeBehind="Export2Excel.a ...

  8. 十天学习PHP之第四天

    学习目的:学会连接数据库  PHP简直就是一个函数库,丰富的函数使PHP的某些地方相当简单.建议大家down一本PHP的函数手冊,总用得到. 我这里就简单说一下连接MYSQL数据库.  1.mysql ...

  9. android圆形进度条ProgressBar颜色设置

    花样android Progressbar http://www.eoeandroid.com/thread-1081-1-1.html http://www.cnblogs.com/xirihanl ...

  10. Servlet的学习之Filter过滤器技术(1)

    本篇将讲诉Servlet中一项非常重要的技术,Filter过滤器技术.通过过滤器,可以对来自客户端的请求进行拦截,进行预处理或者对最终响应给客户端的数据进行处理后再输出. 要想使用Filter过滤器, ...