{"id":1319,"date":"2024-06-03T15:03:26","date_gmt":"2024-06-03T07:03:26","guid":{"rendered":"https:\/\/blog.quantoyo.com\/?p=1319"},"modified":"2024-06-03T15:03:26","modified_gmt":"2024-06-03T07:03:26","slug":"java%e5%bf%ab%e9%80%9f%e5%88%a4%e6%96%b7%e6%aa%94%e6%a1%88%e6%98%af%e4%b8%8d%e6%98%af%e5%bd%b1%e5%83%8f","status":"publish","type":"post","link":"https:\/\/blog.quantoyo.com\/?p=1319","title":{"rendered":"JAVA\u5feb\u901f\u5224\u65b7\u6a94\u6848\u662f\u4e0d\u662f\u5f71\u50cf"},"content":{"rendered":"\n<p>\u53ef\u4ee5\u4f7f\u7528\u5167\u5efa\u51fd\u5f0f\u5eab\u4e2d\u7684 javax.activation.MimetypesFileTypeMap \u4f86\u8655\u7406<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>\u6b64\u65b9\u6cd5\u53ea\u80fd\u5feb\u901f\u7684\u5224\u65b7\u6a94\u6848\u985e\u578b\uff0c\u7576\u7136\u4e0d\u6b62image\uff0c\u9084\u6709\u5176\u4ed6\u66f4\u591a\u6a94\u6848\u985e\u578b\uff0c\u6709\u8208\u8da3\u53ef\u4ee5\u53c3\u8003\uff0c\u9019\u4e3b\u8981\u662f\u62ff\u4f86\u5224\u65b7\u7db2\u8def\u4e0a\u6a94\u6848\u7528\u7684\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background has-small-font-size\"><code>application\/javascript js\napplication\/msword doc docx docm\napplication\/pdf pdf\napplication\/postscript ai eps ps\napplication\/rss+xml rss\napplication\/rtf rtf\napplication\/vnd.ms-excel xls xlsx xlsm XLS\napplication\/vnd.ms-powerpoint ppt pps pot pptx pptm\napplication\/vnd.oasis.database odb\napplication\/vnd.oasis.opendocument.text odt\napplication\/vnd.oasis.presentation odp\napplication\/vnd.oasis.spreadsheet ods\napplication\/vnd.oasis.text odt\napplication\/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx\napplication\/vnd.openxmlformats-officedocument.wordprocessingml.document docx\napplication\/x-awk awk\napplication\/x-blender blend\napplication\/x-cd-image iso\napplication\/x-compress zip gz tar rar\napplication\/x-deb deb\napplication\/x-font-otf otf OTF\napplication\/x-font-ttf ttf TTF\napplication\/x-java-applet class\napplication\/x-java-archive jar\napplication\/xml xml\napplication\/x-ms-dos-executable exe msi\napplication\/x-perl pl\napplication\/x-php php\napplication\/x-rpm rpm\napplication\/x-sharedlib o\napplication\/x-shellscript sh\napplication\/x-tar tar\napplication\/x-texinfo texinfo texi\napplication\/x-tex tex\napplication\/x-trash autosave\napplication\/x-troff t tr roff\napplication\/x-vnd.oasis.opendocument.spreadsheet ods\napplication\/zip zip\naudio\/ac3 ac3\naudio\/basic au\naudio\/midi midi mid\naudio\/mpeg mp3 mpeg3\naudio\/x-aifc aifc\naudio\/x-aiff aif aiff\naudio\/x-generic wav wma mp3 ogg\naudio\/x-mpeg mpeg mpg\naudio\/x-wav wav\nimage\/gif gif GIF\nimage\/ief ief\nimage\/jpeg jpeg jpg jpe JPG\nimage\/png png PNG\nimage\/svg+xml svg svgz\nimage\/tiff tiff tif\nimage\/x-eps eps\nimage\/x-generic bmp jpg jpeg png tif tiff xpm wmf emf\nimage\/x-xwindowdump xwd\ntext\/css css\ntext\/csv csv\ntext\/html html htm HTML HTM\ntext\/plain txt text TXT TEXT\ntext\/richtext rtx\ntext\/rtf rtf\ntext\/tab-separated-values tsv tab\ntext\/x-bibtex bib\ntext\/x-c++hdr h\ntext\/x-csrc c\ntext\/x-c++src cpp c++\ntext\/x-java java\ntext\/x-log log\ntext\/xml xml XML osm\ntext\/x-pascal pas\ntext\/x-po po pot\ntext\/x-python py\ntext\/x-sql sql\ntext\/x-tcl tcl\ntext\/x-tex tex\nvideo\/mpeg mpeg mpg mpe mpv vbs mpegv\nvideo\/msvideo avi\nvideo\/quicktime qt mov moov\nvideo\/x-generic wmv mpeg mp4 ogv swf mov dvd osp\nvideo\/x-msvideo avi<\/code><\/pre>\n\n\n\n<p>\u6211\u5011\u53ea\u9700\u8981\u5224\u65b7\u662f\u5426\u70baimage \u958b\u982d\u5373\u53ef<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background has-small-font-size\"><code>package DefaultPackage;\n\nimport javax.activation.MimetypesFileTypeMap;\nimport java.io.File;\n\nclass ImageTester {\n\tpublic static void main(String&#91;] args) {\n\t\tImageTester it = new ImageTester();\n\t\tString filepath = \"\/Users\/quanto\/Git\/Qu_Photo\/PhotoInfo_1.0.0.jar\";\n\n\t\tif (ImageTester.isImage(filepath))\n\t\t\tSystem.out.println(\"It's an image\");\n\t\telse\n\t\t\tSystem.out.println(\"It's NOT an image\");\n\n\t\tfilepath = \"\/Users\/quanto\/Git\/Qu_Photo\/2024-04-28_135938.JPG\";\n\t\tif (ImageTester.isImage(filepath))\n\t\t\tSystem.out.println(\"It's an image\");\n\t\telse\n\t\t\tSystem.out.println(\"It's NOT an image\");\n\t}\n\n\tpublic static Boolean isImage(String filepath) {\n\t\tFile f = new File(filepath);\n\t\tString mimetype = new MimetypesFileTypeMap().getContentType(f);\n\t\tString type = mimetype.split(\"\/\")&#91;0];\n\t\tif (type.equals(\"image\"))\n\t\t\treturn true;\n\t\telse\n\t\t\treturn false;\n\t}\n\n\tpublic static Boolean isImage(File f) {\n\t\tString mimetype = new MimetypesFileTypeMap().getContentType(f);\n\t\tString type = mimetype.split(\"\/\")&#91;0];\n\t\tif (type.equals(\"image\"))\n\t\t\treturn true;\n\t\telse\n\t\t\treturn false;\n\t}\n}\n\n\u6b64\u7bc4\u4f8b\u4e2d\uff0c\u6703\u5148show \u51fa It's an image\n\u518d\u63a5\u8457 show \u51fa It's NOT an image<\/code><\/pre>\n\n\n\n<p>\u5229\u7528\u9019\u500b\u5de5\u5177\u53ef\u4ee5\u4f7f\u7528\u539f\u751fjava \u5feb\u901f\u5224\u65b7\u6a94\u6848\u985e\u578b<\/p>\n\n\n\n<p>\u53c3\u8003\u8cc7\u6599\uff1ahttps:\/\/github.com\/jjYBdx4IL\/misc\/blob\/master\/text-utils\/src\/main\/resources\/com\/github\/jjYBdx4IL\/utils\/text\/mimetypes.txt<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u53ef\u4ee5\u4f7f\u7528\u5167\u5efa\u51fd\u5f0f\u5eab\u4e2d\u7684 javax.activation.MimetypesFileTypeMap \u4f86\u8655\u7406<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[184,183,8,181,180,185,182],"class_list":["post-1319","post","type-post","status-publish","format-standard","hentry","category-technology","tag-file-type","tag-image","tag-java","tag-javax-activation-mimetypesfiletypemap","tag-mimetypesfiletypemap","tag-185","tag-182"],"_links":{"self":[{"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/posts\/1319","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1319"}],"version-history":[{"count":1,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/posts\/1319\/revisions"}],"predecessor-version":[{"id":1320,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/posts\/1319\/revisions\/1320"}],"wp:attachment":[{"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1319"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}