1    package com.instantbank.collections.util;
2    
3    import java.io.File;
4    import java.io.FileInputStream;
5    import java.io.FileOutputStream;
6    import java.io.IOException;
7    
8    public class FileServices extends Object {
9    
10     public FileServices() { }
11   
12   
13     public void copy(String file, String sourcePath, String targetPath) throws IOException {
14       String target = null;
15       String source = null;
16       FileOutputStream targetFile = null;
17       FileInputStream sourceFile = null;
18   
19       try {
20         int n;
21         byte[] buff = new byte[1024];
22   
23         source = sourcePath + file;
24         target = targetPath + file;
25   
26         try {
27           sourceFile = new FileInputStream(source);
28           targetFile = new FileOutputStream(target);
29         }
30         catch(IOException e) {
31           throw e;
32         }
33   
34         while((n = sourceFile.read(buff)) > 0) {
35           targetFile.write(buff, 0, n);
36         }
37   
38         sourceFile.close();
39         targetFile.close();
40   
41       }
42       catch(IOException e) {
43         throw e;
44       }
45     }
46   
47   
48     public void delete(String file, String path) throws Exception {
49       String source;
50       File theFile = null;
51   
52       try {
53         source = path + file;
54   
55         theFile = new File(source);
56   
57         theFile.delete();
58   
59       }
60       catch(Exception e) {
61         throw e;
62       }
63     }
64   
65   
66     public void move(String file, String sourcePath, String targetPath) throws Exception, IOException {
67       copy(file, sourcePath, targetPath);
68       delete(file, sourcePath);
69     }
70   
71   }
72   
73