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 阅读(121) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航:
 

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

常用链接

留言簿(1)

随笔分类

随笔档案

PL/SQL存储过程与函数

搜索

  •  

最新评论

阅读排行榜

评论排行榜