1 6 7 package com.quikj.application.communicator.applications.webtalk.model; 8 9 import java.io.*; 10 14 public class FileUtilities { 15 16 17 public FileUtilities() { 18 } 19 20 public boolean fileCopy(File inFile, File outFile) throws IOException { 21 22 if (inFile.getCanonicalPath().equals(outFile.getCanonicalPath())) { 23 System.out.println("Source and destination file same. No copying required"); 26 27 return false; 28 } 29 30 FileInputStream fin = new FileInputStream(inFile); 31 FileOutputStream fout = new FileOutputStream(outFile); 32 StreamCopy(fin, fout); 33 fin.close(); 34 fout.close(); 35 36 return true; 37 } 38 39 public String getDirName (String fileType,File file) 40 { 41 String dir = ""; 42 String name = file.getName(); 43 if (fileType.equals("htmlFile")) 44 { 45 46 if((name.endsWith(".htm")) || (name.endsWith(".html")) 47 || (name.endsWith(".HTM")) || (name.endsWith(".HTML"))) 48 { 49 dir = "html"; 50 } 51 52 } 53 else if (fileType.equals("imageFile")) 54 { 55 if((name.endsWith(".gif")) || (name.endsWith(".jpeg")) 56 ||(name.endsWith(".jpg")) || (name.endsWith(".png")) 57 ||(name.endsWith(".GIF")) || (name.endsWith(".JPG")) 58 ||(name.endsWith(".JPEG")) || (name.endsWith(".PNG"))) 59 { 60 dir = "icons"; 61 } 62 63 } 64 65 return dir ; 66 67 } 68 69 private void StreamCopy(InputStream in, OutputStream out) 70 throws IOException { 71 72 76 synchronized (in) { 77 synchronized (out) { 78 79 byte[] buffer = new byte[1024]; 80 while (true) { 81 int bytesRead = in.read(buffer); 82 if (bytesRead == -1) break; 83 out.write(buffer, 0, bytesRead); 84 } 85 } 86 } 87 } 88 89 } 90 | Popular Tags |