如何在Java中使用FileNameMap接口? [英] How to use FileNameMap interface in Java?
本文介绍了如何在Java中使用FileNameMap接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此接口提供一种方法,即getContentTypeFor(String fileName).但是,我不知道如何使用它.我在Eclipse中实现了界面并以:
This interface provides one method, namely getContentTypeFor(String fileName). However, I have no idea how to use it. I implemented interface in Eclipse and ended with:
import java.net.FileNameMap;
public class Fnam implements FileNameMap {
public static void main(String[] args) {
}
@Override
public String getContentTypeFor(String fileName) {
return null;
}
}
该方法返回null.我应该如何更改它以获得MIME类型?
The method returns null. How should I change it to get the MIME type ?
推荐答案
它是JDK内部实现的接口,在大多数情况下,您应该仅使用接口实现,而不是接口本身.
It is interface for inner implementation of JDK, and in most cases you should use just interface implementation, not interface itself.
以下是简单的用法示例:
Here simple sample of usage:
public class Main {
private static FileNameMap fileNameMap = URLConnection.getFileNameMap();
public static void main(String... str) {
System.out.print(fileNameMap.getContentTypeFor("my_file.xml"));
}
}
打印:
application/xml
和似乎仅
And seems only MimeTable
is only current implementation of that interface in JDK.
这篇关于如何在Java中使用FileNameMap接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文