失樂園

          技術之路

          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 狄浩 閱讀(151) 評論(0)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 海门市| 达尔| 清水河县| 齐河县| 福海县| 多伦县| 民丰县| 张家港市| 麟游县| 凌源市| 东丽区| 城市| 佛学| 盐津县| 宁乡县| 天等县| 安岳县| 光泽县| 九江市| 阳高县| 楚雄市| 安溪县| 石河子市| 井研县| 乐亭县| 宜章县| 七台河市| 玉门市| 汾阳市| 丽江市| 彩票| 鞍山市| 平潭县| 平乐县| 油尖旺区| 香河县| 土默特左旗| 绥棱县| 乌兰浩特市| 垫江县| 阳西县|