JAVA
파일 확장자 판별 하기
KIMSG
2017. 7. 21. 14:13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | public static String fileType(String storedFileName) { /*확장자 추출하기*/ String[] values = storedFileName.split("\\."); String[] imgFormat = {"jpg" ,"jpeg" , "jpe" , "png"} ; String[] docFormat = {"doc" ,"hwp" , "html" , "xls", "zip", "alz", "egg"} ; String img = "IMG"; String doc = "DOC"; String pdf = "PDF"; /*확장자 판별*/ for(int i=0; i< imgFormat.length; i++){ if(values[1].equals(imgFormat[i])){ return img; } } for(int i=0; i< docFormat.length; i++){ if(values[1].equals(docFormat[i])){ return doc; } } if (values[1].equals(pdf)) { return pdf; } return values[1]; } | cs |