posts - 33,  comments - 17,  trackbacks - 0
           1/**
           2     * 拷貝一個(gè)目錄或者文件到指定路徑下
           3     * 
           4     * @param source
           5     * @param target
           6     */

           7    public static void copy(File source, File target)
           8    {
           9        File tarpath = new File(target, source.getName());
          10        if (source.isDirectory())
          11        {
          12            tarpath.mkdir();
          13            File[] dir = source.listFiles();
          14            for (int i = 0; i < dir.length; i++)
          15            {
          16                copy(dir[i], tarpath);
          17            }

          18        }

          19        else
          20        {
          21            try
          22            {
          23                InputStream is = new FileInputStream(source);
          24                OutputStream os = new FileOutputStream(tarpath);
          25                byte[] buf = new byte[1024];
          26                int len = 0;
          27                while ((len = is.read(buf)) != -1)
          28                {
          29                    os.write(buf, 0, len);
          30                }

          31                is.close();
          32                os.close();
          33            }

          34            catch (FileNotFoundException e)
          35            {
          36                e.printStackTrace();
          37            }

          38            catch (IOException e)
          39            {
          40                e.printStackTrace();
          41            }

          42        }

          43    }
          posted on 2008-07-23 17:29 scea2009 閱讀(133) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           

          <2008年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          PL/SQL存儲(chǔ)過程與函數(shù)

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 上饶市| 枝江市| 四子王旗| 亚东县| 丹江口市| 德江县| 仪征市| 土默特左旗| 县级市| 汉川市| 东乌| 辽中县| 通道| 包头市| 桑日县| 琼海市| 襄汾县| 大安市| 南阳市| 乐陵市| 林州市| 平潭县| 连云港市| 滨州市| 偏关县| 平定县| 东乌珠穆沁旗| 原阳县| 庆元县| 桐城市| 竹溪县| 青冈县| 浑源县| 和硕县| 福泉市| 浮山县| 北流市| 石台县| 秦安县| 宁晋县| 玉环县|