KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quikj > application > utilities > postinstall > FileUtils


1 /*
2  * FileUtils.java
3  *
4  * Created on November 7, 2003, 6:58 AM
5  */

6
7 package com.quikj.application.utilities.postinstall;
8
9 import java.io.*;
10 import java.util.*;
11
12 /**
13  *
14  * @author amit
15  */

16 public class FileUtils
17 {
18     /** Creates a new instance of FileUtils */
19     public FileUtils()
20     {
21     }
22   
23     public static void copy(String JavaDoc src, String JavaDoc dest)
24     throws FileNotFoundException, IOException
25     {
26         FileInputStream fis = new FileInputStream(src);
27         FileOutputStream fos = new FileOutputStream(dest);
28         byte[] buffer = new byte[1000];
29         
30         int size;
31         while ((size = fis.read(buffer)) > 0)
32         {
33             fos.write(buffer, 0, size);
34         }
35         fos.close();
36         fis.close();
37     }
38         
39     public static void list(File first,
40     File base,
41     String JavaDoc[] suffixes,
42     String JavaDoc[] excludes,
43     ArrayList list)
44     throws FileNotFoundException, IOException
45     {
46         File[] listing = base.listFiles();
47         for (int i = 0; i < listing.length; i++)
48         {
49             if ((listing[i].getName().equals(".") == true) ||
50             (listing[i].getName().equals("..") == true))
51             {
52                 continue;
53             }
54             
55             if (listing[i].isDirectory() == true)
56             {
57                 boolean l = false;
58                 
59                 if (excludes == null)
60                 {
61                     l = true;
62                 }
63                 else
64                 {
65                     int j;
66                     for (j = 0; j < excludes.length; j++)
67                     {
68                         File dir = new File (first, excludes[j]);
69 // System.out.println (listing[i].getAbsolutePath() + "------"
70
// + dir.getAbsolutePath());
71
if (listing[i].getAbsolutePath().equals(dir.getAbsolutePath())
72                         == true)
73                         {
74                             // match
75
l = false;
76                             break;
77                         }
78                     }
79                     
80                     if (j == excludes.length) // not found in the excludes list
81
{
82                         l = true;
83                     }
84                 }
85                 
86                 if (l == true)
87                 {
88                     list(first, listing[i], suffixes, excludes, list);
89                 }
90                 continue;
91             }
92             
93             // it is a file
94
boolean l = false;
95             if (suffixes == null)
96             {
97                 l = true;
98             }
99             else
100             {
101                 for (int j = 0; j < suffixes.length; j++)
102                 {
103                     if (listing[i].getName().endsWith(suffixes[j]) == true)
104                     {
105                         l = true;
106                         break;
107                     }
108                 }
109             }
110             
111             
112             if (l == true)
113             {
114                 list.add(listing[i].getAbsolutePath());
115             }
116         }
117     }
118     
119 }
120
Popular Tags