Đang chuẩn bị liên kết để tải về tài liệu:
Java 6 Platform Revealed phần 2

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Tham khảo tài liệu 'java 6 platform revealed phần 2', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 6 CHAPTER 1 JAVA SE 6 AT A GLANCE As soon as a hit is found for your mime type searching stops. Note See the javadoc for the MailcapCommandMap class for information on the format of the .mailcap file. Another thing you can do with the Activation Framework is map files to mime types. This is something your e-mail client typically does to see if it knows how to handle a particular attachment. The program in Listing 1-2 displays the mime types that it thinks are associated with the files in a directory identified from the command line. Listing 1-2. Getting the File Type Map import javax.activation. import java.io. public class FileTypes public static void main String args FileTypeMap map FileTypeMap.getDefaultFileTypeMap String path if args.length 0 path . else path args 0 File dir new File path File files dir.listFiles for File file files System.out.println file.getName map.getContentType file The default implementation of the FileTypeMap class is its MimetypesFileTypeMap subclass. This does a mapping of file extensions to mime types. Theoretically you could create your own subclass that examined the first few bytes of a file for its magic signature for instance 0XCAFEBABE for .class files . The output from running the program is dependent on the directory you run it against. With no command-line argument the current directory is used as the source CHAPTER 1 JAVA SE 6 AT A GLANCE 7 java FileTypes tmp ack.jpg image jpeg addr.html text html alabama.gif image gif alarm.wav audio x-wav alex.txt text plain alt.tif image tiff With the JavaMail API you would typically create a DataHandler for the part of the multipart message associating the content with the mime type String text . DataHandler handler new DataHandler text text plain BodyPart part new MimeBodyPart part.setDataHandler handler Under the covers this would use the previously mentioned maps. If the system didn t know about the mapping of file extension to mime type you would have to add it to the map allowing the