posts - 33,  comments - 17,  trackbacks - 0
           1/**
           2     * 拷貝一個目錄或者文件到指定路徑下
           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 閱讀(134) 評論(0)  編輯  收藏

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


          網站導航:
           

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

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

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

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 尉犁县| 苏尼特左旗| 德庆县| 睢宁县| 博客| 兴文县| 宁化县| 新疆| 星子县| 仁化县| 山西省| 莲花县| 安福县| 萨迦县| 宜川县| 夹江县| 江陵县| 赤城县| 明星| 遵义市| 青阳县| 泸西县| 南召县| 察哈| 武鸣县| 大城县| 浏阳市| 应用必备| 青川县| 涞源县| 新乡县| 商南县| 本溪市| 顺昌县| 夹江县| 牟定县| 高台县| 丰镇市| 将乐县| 禹城市| 新建县|