Java ile Mime Type Tespiti
Dosyanın hangi aileye ait olduğunu tespit eden java kodları
String fileName = "/path/to/file";
MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
// only by file name
String mimeType = mimeTypesMap.getContentType(fileName);
// or by actual File instance
File file = new File(fileName);
mimeType = mimeTypesMap.getContentType(file);
MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
// only by file name
String mimeType = mimeTypesMap.getContentType(fileName);
// or by actual File instance
File file = new File(fileName);
mimeType = mimeTypesMap.getContentType(file);
Bir başka örnek
import java.net.*;
public class GetMimeType {
public static void main(String[] args) {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
String mimeType = fileNameMap.getContentTypeFor("alert.gif");
System.out.println("mimeType="+ mimeType);
}
}
public class GetMimeType {
public static void main(String[] args) {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
String mimeType = fileNameMap.getContentTypeFor("alert.gif");
System.out.println("mimeType="+ mimeType);
}
}
Kaynak
- http://stackoverflow.com/questions/51438/getting-a-files-mime-type-in-java
- http://www.roseindia.net/java/java-get-example/get-mime-type.shtml
Yorumunuzu Ekleyin