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. DE1-SOC连接设定

    将电源供应器插上电源接口. 使用白色的USB Type B线材将计算机与DE1-SoC上的USB-Blaster II接口连接.此接口主要负责FPGA配置以及HPS Debug使用. 使用Mini-U ...

  2. 数论(容斥原理)hdu-4509-The Boss on Mars

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4059 题目大意: 给一个n,求1~n中与n互质的数的4次方的总和. 解题思路: 容斥原理.逆元.公式 ...

  3. Corrupted MAC on input at /usr/local/perl/lib/site_perl/5.22.1/x86_64-linux/Net/SSH/Perl/Packet.pm l

    <pre name="code" class="python">[Thu May 5 11:02:27 2016] [error] Corrupte ...

  4. 对base-adapter-helper的简单分析

    在微博上看到了这篇Android ListView适配器应该这样写,受益匪浅. 于是依据文章结尾的介绍来到了base-adapter-helper的github,地址:https://github.c ...

  5. QLinkedList和std::forward_list(都是双向链表,不支持operator[],好处可能是插入和删除都比较快)

    forward_list forward_list是C++11版本才有的.forward_list被实现为单链表,而list是一个双向链表,所以forward_list要比list高效一些.forwa ...

  6. ModelAndView

    我给你改一下public ModelAndView showDept(HttpServletRequest req,HttpServletResponse resp,ModelMap model){ ...

  7. HNCU1330:算法3-1:八进制数

    http://hncu.acmclub.com/index.php?app=problem_title&id=111&problem_id=1330 题目描述 将十进制数转换为八进制, ...

  8. Swift - 异步加载各网站的favicon图标,并在单元格中显示

    下面是一个简单的应用,表格视图的各个单元格自动异步加载各个网站的favicon图标,并显示出来. 主要是复习下如何自定义单元格,单元格中图片的异步加载,以及didSet的用法. 效果图如下: 操作步骤 ...

  9. 在Centos下安装matlab

    首先科普一下什么事matlab MATLAB是美国MathWorks公司出品的商业数学软件,用于算法开发.数据可视化.数据分析以及数值计算的高级技术计算语言和交互式环境,主要包含MATLAB和Simu ...

  10. C#_事件

    C#_事件 概述 今天用来演示事件的例子是模拟实现一个文件下载类,在这个类中我将定义一个DownLoad事件,这个事件用来在文件下载的过程中,向订阅这个事件的用户发出消息,而这个消息将用DownLoa ...