/Users/lyon/j4p/src/net/server/servlets/FileUtil.java

1    package net.server.servlets; 
2     
3    import java.io.*; 
4    import java.util.Properties; 
5     
6     
7    /** 
8     *  File Utility Class 
9     */ 
10    
11   public class FileUtil { 
12    
13    
14       /** 
15        * FileUtil() Constructor 
16        * 
17        * Don't let anyone instantiate this class 
18        */ 
19    
20       private FileUtil() { 
21       } 
22    
23    
24       /** 
25        * Returns an instance of a File 
26        * 
27        * @return        File 
28        */ 
29    
30       public static File getFile(String f) { 
31    
32           return new File(f); 
33       } 
34    
35    
36       /** 
37        * Returns an instance of a Property 
38        * @return        Properties 
39        */ 
40    
41       public static Properties loadProperties(String f) 
42               throws PropFileException { 
43           Properties prop = new Properties(); 
44    
45           try { 
46               FileInputStream fs = getFileInputStream(f); 
47               prop.load(fs); 
48               fs.close(); 
49           } catch (FileNotFoundException pfnf) { 
50               throw new PropFileException(); 
51           } catch (IOException io) { 
52               throw new PropFileException(); 
53           } 
54    
55           return prop; 
56       } 
57    
58    
59       /** 
60        * Returns an instance of a FileInputStream 
61        * 
62        * @return        FileInputStream 
63        */ 
64    
65       public static FileInputStream getFileInputStream(String f) 
66               throws FileNotFoundException, IOException { 
67    
68           return new FileInputStream(f); 
69       } 
70    
71    
72       /** 
73        * Returns an instance of a BufferedReader 
74        * 
75        * @return        BufferedReader 
76        */ 
77    
78       public static BufferedReader openInputFile(File f) 
79               throws FileNotFoundException, IOException { 
80    
81           return (new BufferedReader(new FileReader(f))); 
82       } 
83    
84    
85       /** 
86        * Returns an instance of a BufferedWriter 
87        * @return        BufferedWriter 
88        */ 
89    
90       public static BufferedWriter openOutputFile(File f) 
91               throws FileNotFoundException, IOException { 
92    
93           return (new BufferedWriter(new FileWriter(f))); 
94       } 
95    
96    
97       /** 
98        * Closes the BufferedReader 
99        * 
100       */ 
101   
102      public static void close(BufferedReader br) { 
103   
104          try { 
105              br.close(); 
106          } catch (IOException io) { 
107          } 
108   
109      } 
110   
111   
112      /** 
113       * Closes the BufferedWriter 
114       * 
115       */ 
116   
117      public static void close(BufferedWriter bw) { 
118   
119          try { 
120              bw.close(); 
121          } catch (IOException io) { 
122          } 
123   
124      } 
125   
126      /** 
127       * println() Method 
128       * 
129       * Appends the object to the BufferedWriter 
130       * 
131       */ 
132   
133      public static void println(BufferedWriter bw, Object o) { 
134   
135          try { 
136              bw.write(o + "\n"); 
137          } catch (IOException io) { 
138          } 
139   
140      } 
141   
142  } 
143