失樂園

          技術之路

          BlogJava 聯系 聚合 管理
            19 Posts :: 44 Stories :: 40 Comments :: 0 Trackbacks
          import java.io.*;
          import java.util.*;
          import java.text.SimpleDateFormat;

          public class FileDev02 
          {    
              
          private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日HH時mm分ss秒");

              
          public static void copyUtil(String from,String to){
                  
          try
                  {
                      File source 
          = new File(from);
                      File destiny 
          = new File(to);
                      FileInputStream fis 
          = new FileInputStream(source);
                      BufferedInputStream bis 
          = new BufferedInputStream(fis);

                      
          if (!destiny.exists())
                      {
                          destiny.createNewFile();
                      }
                      FileOutputStream fos 
          = new FileOutputStream(to);
                      BufferedOutputStream bos 
          = new BufferedOutputStream(fos);

                      
          byte[] b = new byte[2048];
                      
          int len;
                      
          while ((len=fis.read(b))>0)
                      {
                          fos.write(b,
          0,len);
                          len 
          = 0;
                      }
                  }
                  
          catch (Exception e)
                  {
                      e.printStackTrace();
                  }
              }
              
              
          public static void bufferCopyUtil(String from,String to){
                  
          try
                  {
                      File source 
          = new File(from);
                      File destiny 
          = new File(to);
                      FileInputStream fis 
          = new FileInputStream(source);
                      BufferedInputStream bis 
          = new BufferedInputStream(fis);

                      
          if (!destiny.exists())
                      {
                          destiny.createNewFile();
                      }
                      FileOutputStream fos 
          = new FileOutputStream(to);
                      BufferedOutputStream bos 
          = new BufferedOutputStream(fos);

                      
          int len = 0;
                      
          byte[] b = new byte[4096];
                      
          while (true)
                      {
                          len 
          = bis.read(b);
                          
          if (len<=0)
                          {
                              
          break;
                          }
                          bos.write(b,
          0,len);
                      }
                      bos.flush();
                      bos.close();
                      fos.close();
                      bis.close();
                      fis.close();
                  }
                  
          catch (Exception e)
                  {
                      e.printStackTrace();
                  }
              }

              
          public static void main(final String[] args) 
              {    
                  
          try
                  {
                      
          long l1 = System.currentTimeMillis();
                      bufferCopyUtil(
          "FarmFrenzy3.exe","D:/開心農場.exe");
                      
          long l2 = System.currentTimeMillis();
                      
          long cost = (l2 - l1)/1000l;
                      System.out.println(cost);
                  }
                  
          catch (Exception e)
                  {
                      e.printStackTrace();
                  }
                  
          /*System.out.println(File.pathSeparator);
                  System.out.println(File.pathSeparatorChar);
                  System.out.println(File.separator);
                  System.out.println(File.separatorChar);
                  try
                  {
                      File f = new File("CalendarTest.java");
                      long lastM = f.lastModified();
                      Calendar cal = Calendar.getInstance();
                      
                      cal.setTimeInMillis(lastM);
                      Date d = cal.getTime();
                      System.out.println(sdf.format(d));
                      System.out.println(cal.getMinimalDaysInFirstWeek());
                      System.out.println(cal.getMinimum(Calendar.DAY_OF_WEEK));
                      System.out.println(cal.getTimeZone().getID());
                      File ff = new File("tt/kk");
                      File fff = new File("Tir");
                      boolean $b = f.mkdir();
                      boolean b = ff.mkdirs();
                      System.out.println($b);
                      System.out.println(b);
                      boolean $$b = f.renameTo(fff);
          */

                  }
                  
          /*try
                  {
                      File file = new File(".");
                      String[] fileNames;
                      if (args.length==0)
                      {
                          fileNames = file.list();
                      }else{
                          fileNames = file.list(new CusFilter(args[0]){
                              class CusFilter implements FilenameFilter
                              {
                                  public boolean accept(File f,String name){
                                      String s = new File(name).getName();
                                      return s.indexOf(args[0])!=-1;
                                  }
                              }
                          });
                      }
                  }
                  catch (Exception e)
                  {
                      e.printStackTrace();
                  }
          */
                  
              }
          posted on 2010-11-18 15:07 狄浩 閱讀(152) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 兴隆县| 界首市| 高要市| 甘肃省| 个旧市| 肥城市| 临夏县| 万宁市| 莫力| 固镇县| 梅河口市| 永顺县| 昭通市| 连平县| 炎陵县| 安陆市| 松阳县| 新巴尔虎右旗| 苍梧县| 连平县| 建昌县| 玛纳斯县| 满洲里市| 思茅市| 宜丰县| 定边县| 团风县| 衢州市| 盐津县| 木兰县| 秭归县| 金昌市| 依安县| 鹤庆县| 天祝| 肇州县| 奉新县| 阳江市| 宜都市| 安乡县| 上栗县|