1 21 package org.lobobrowser.util.io; 22 23 import java.io.*; 24 25 public class Files { 26 private Files() { 27 } 28 29 33 public static String getContentType(File file) { 34 String name = file.getName(); 36 int dotIdx = name.lastIndexOf('.'); 37 String extension = dotIdx == -1 ? null : name.substring(dotIdx+1); 38 if("txt".equalsIgnoreCase(extension)) { 39 return "text/plain; charset=\"" + System.getProperty("file.encoding") + "\""; 40 } 41 if("html".equalsIgnoreCase(extension) || "htm".equalsIgnoreCase(extension)) { 42 return "text/html; charset=\"" + System.getProperty("file.encoding") + "\""; 43 } 44 else { 45 return "application/octet-stream"; 46 } 47 } 48 } 49 | Popular Tags |