1 20 21 package org.jdesktop.jdic.filetypes.internal; 22 23 import java.net.URL ; 24 25 28 public class AppUtility { 29 30 33 private AppUtility() {} 34 35 45 public static String getFileExtensionByURL(URL url) { 46 String trimFile = url.getFile().trim(); 47 48 if (trimFile == null || trimFile == "" || trimFile == "/") { 49 return null; 50 } 51 52 int strIndex = trimFile.lastIndexOf("/"); 53 String filePart = trimFile.substring(strIndex + 1, trimFile.length()); 54 55 strIndex = filePart.lastIndexOf("."); 56 if (strIndex == -1 || strIndex == filePart.length() - 1) { 57 return null; 58 } else { 59 String fileExt = filePart.substring(strIndex, filePart.length()); 60 61 return fileExt; 62 } 63 } 64 65 71 public static String removeDotFromFileExtension(String fileExt) { 72 String temFileExt = fileExt; 73 if (fileExt.charAt(0) == '.') { 74 temFileExt = fileExt.substring(1, fileExt.length()); 75 } 76 77 return temFileExt; 78 } 79 80 87 public static String addDotToFileExtension(String fileExt) { 88 String temFileExt = fileExt; 89 if (fileExt.charAt(0) != '.') { 90 String dotStr = "."; 91 temFileExt = dotStr.concat(fileExt); 92 } 93 94 return temFileExt; 95 } 96 } 97 98 99 | Popular Tags |