{"id":1574,"date":"2024-11-26T15:39:58","date_gmt":"2024-11-26T07:39:58","guid":{"rendered":"https:\/\/note.ui11.cc\/?p=1574"},"modified":"2024-11-26T15:50:03","modified_gmt":"2024-11-26T07:50:03","slug":"file%e7%9a%84%e5%b8%b8%e8%a7%81%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/note.ui11.cc\/index.php\/2024\/11\/26\/file%e7%9a%84%e5%b8%b8%e8%a7%81%e6%96%b9%e6%b3%95\/","title":{"rendered":"File\u7684\u5e38\u89c1\u65b9\u6cd5"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/note.ui11.cc\/wp-content\/uploads\/2024\/11\/image-148-1024x536.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"536\" data-original=\"https:\/\/note.ui11.cc\/wp-content\/uploads\/2024\/11\/image-148-1024x536.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-1575\"  sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/div><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>package com.file.test;\n\nimport java.io.File;\nimport java.text.SimpleDateFormat;\n\npublic class Filetest02 {\n    public static void main(String&#91;] args) {\n        File file = new File(\"D:\\\\\u8d44\u6e90\u56fe\u7247\\\\\u4e3b\u56fe\");\n        \/\/\u5224\u65ad\u5f53\u524d\u6587\u4ef6\u5bf9\u8c61\uff0c\u5bf9\u5e94\u7684\u6587\u4ef6\u8def\u5f84\u662f\u5426\u5b58\u5728\uff0c\u5b58\u5728\u8fd4\u56detrue\n        System.out.println(\"\u5224\u65ad\u5f53\u524d\u6587\u4ef6\u5bf9\u8c61\uff0c\u5bf9\u5e94\u7684\u6587\u4ef6\u8def\u5f84\u662f\u5426\u5b58\u5728\uff0c\u5b58\u5728\u8fd4\u56detrue\");\n        boolean exists = file.exists();\n        System.out.println(exists);\n        System.out.println(\"\u5224\u65ad\u5f53\u524d\u5bf9\u8c61\u6307\u5b9a\u7684\u662f\u4e0d\u662f\u6587\u4ef6\uff0c\u662f\u5219\u8fd4\u56detrue\");\n        boolean file1 = file.isFile();\n        System.out.println(file1);\n        System.out.println(\"\u5224\u65ad\u5f53\u524d\u5bf9\u8c61\u6307\u4ee3\u6587\u4ef6\u662f\u5426\u4e3a\u6587\u4ef6\u5939,\u662f\u5c31\u8fd4\u56detrue\");\n        boolean directory = file.isDirectory();\n        System.out.println(directory);\n        System.out.println(\"\u5224\u65ad\u5f53\u524d\u5bf9\u8c61\u6587\u4ef6\u7684\u540d\u79f0\u5305\u542b\u540e\u7f00\");\n        String name = file.getName();\n        System.out.println(name);\n        System.out.println(\"\u83b7\u53d6\u6587\u4ef6\u7684\u6700\u540e\u4fee\u6539\u65f6\u95f4\");\n        long l = file.lastModified();\n        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss\");\n        System.out.println(l);\n        System.out.println( simpleDateFormat.format(l));\n        System.out.println(\"\u83b7\u53d6\u521b\u5efa\u6587\u4ef6\u5bf9\u8c61\u65f6\u4f7f\u7528\u7684\u8def\u5f84\");\n        String path = file.getPath();\n        System.out.println(path);\n        System.out.println(\"\u83b7\u53d6\u7edd\u5bf9\u8def\u5f84\");\n        File absoluteFile = file.getAbsoluteFile();\n        System.out.println(absoluteFile);\n\n    }\n}\n\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/note.ui11.cc\/wp-content\/uploads\/2024\/11\/image-150-1024x324.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"324\" data-original=\"https:\/\/note.ui11.cc\/wp-content\/uploads\/2024\/11\/image-150-1024x324.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-1577\"  sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/div><\/figure>\n\n\n\n<p><strong>\u521b\u5efa\u6587\u4ef6\u548c\u5220\u9664\u6587\u4ef6\u7684\u5e38\u7528\u65b9\u6cd5\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/note.ui11.cc\/wp-content\/uploads\/2024\/11\/image-151.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"976\" height=\"308\" data-original=\"https:\/\/note.ui11.cc\/wp-content\/uploads\/2024\/11\/image-151.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-1578\"  sizes=\"auto, (max-width: 976px) 100vw, 976px\" \/><\/div><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>package com.file.test;\n\nimport java.io.File;\nimport java.io.IOException;\nimport java.sql.SQLOutput;\n\npublic class FileStudy03 {\n    public static void main(String&#91;] args) throws IOException {\n\n        \/\/\u521b\u5efa\u4e00\u4e2a\u65b0\u6587\u4ef6\uff08\u6587\u4ef6\u5185\u5bb9\u4e3a\u7a7a\uff09\uff0c\u521b\u5efa\u6210\u529f\u8fd4\u56detrue\n        File file = new File(\"D:\/VScode\/testFile.txt\");\n        System.out.println(file.createNewFile());\n\n        \/\/\u7528\u4e8e\u521b\u5efa\u4e00\u4e2a\u6587\u4ef6\u5939\u3002\u6ce8\u610f\uff0c\u53ea\u80fd\u521b\u5efa\u4e00\u7ea7\u6587\u4ef6\u5939\n        File file1 = new File(\"D:\/VScode\/AAA\");\n\n        boolean mkdir = file1.mkdir();\n        System.out.println(\"\u521b\u5efa\u6210\u529f\u8fd4\u56detrue\uff0c\u521b\u5efa\u5931\u8d25\u8fd4\u56defalse\");\n        System.out.println(mkdir);\n        \/\/\u7528\u4e8e\u521b\u5efa\u6587\u4ef6\u5939\uff0c\u6ce8\u610f\u53ef\u4ee5\u521b\u5efa\u591a\u7ea7\u6587\u4ef6\u5939\n        System.out.println(\"\u521b\u5efa\u4e8c\u7ea7\u6587\u4ef6\u5939\");\n        File file3 = new File(\"D:\/VScode\/AAA\/bbb\");\n        boolean mkdirs = file3.mkdirs();\n        System.out.println(mkdirs);\n        \/\/\u5220\u9664\u6587\u4ef6\uff0c\u6216\u8005\u6587\u4ef6\u5939\uff0c\u4e0d\u80fd\u5220\u9664\u975e\u7a7a\u6587\u4ef6\u5939\n        System.out.println(\"\u5220\u9664\u6587\u4ef6\u5939\");\n        boolean delete = file.delete();\n        System.out.println(delete);\n        boolean delete1 = file1.delete();\n        System.out.println(delete1);\n        System.out.println(\"\u6587\u4ef6\u5939\u5df2\u5220\u9664\");\n        System.out.println(\"\u5220\u9664\u4e8c\u7ea7\u6587\u4ef6\u5939\");\n        boolean delete2 = file3.delete();\n        System.out.println(delete2);\n        System.out.println(\"\u5220\u9664\u4e00\u7ea7\u6587\u4ef6\u5939\");\n        boolean delete3 = file1.delete();\n        System.out.println(delete3);\n        \/\/\u6ce8\u610f\uff1a\u4e0d\u80fd\u5220\u9664\u975e\u7a7a\u6587\u4ef6\u5939\uff0c\u5982\u679c\u4e00\u7ea7\u6587\u4ef6\u5939\u91cc\u9762\u6709\u53e6\u5916\u4e00\u4e2a\u4e2a\u6587\u4ef6\u5939\u4e5f\u662f\u4e0d\u80fd\u5220\u9664\u7684\n\n\n    }\n}\n<\/code><\/pre>\n\n\n\n<p>File\u5bf9\u8c61\u53ef\u4ee5\u5220\u9664\u4e00\u4e2a\u6587\u4ef6\uff0c\u6587\u4ef6\u5939\uff0c\u4e5f\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u6587\u4ef6\u4ee5\u53ca\u6587\u4ef6\u5939\uff0c\u53ef\u4ee5\u521b\u5efa\u591a\u7ea7\u6587\u4ef6\u5939\uff0c\u7528\u7684\u662fmkdirs,\u521b\u5efa\u5355\u7ea7\u6587\u4ef6\u5939\u7528\u5f97\u662fmkdir\uff0c\u521b\u5efa\u4e00\u4e2a\u6587\u4ef6\u7528\u5f97\u662fcreaNewFile();<\/p>\n\n\n\n<p><strong>\u904d\u5386\u4e00\u7ea7\u6587\u4ef6\u5939<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package com.file.test;\n\nimport java.io.File;\n\npublic class ListTest {\n    public static void main(String&#91;] args) {\n        \/\/\u904d\u5386\u6587\u4ef6\u5939\n        \/\/public String&#91;] list()  \u83b7\u53d6\u5f53\u524d\u76ee\u5f55\u4e0b\u6240\u6709\u7684\u4e00\u7ea7\u6587\u4ef6\u5939\u540d\u79f0\uff0c\u5f97\u5230\u4e00\u4e2a\u5b57\u7b26\u521b\u6570\u7ec4\u53bb\u8fd4\u56de\n\n        File file = new File(\"D:\/\/\");\n        File&#91;] files = file.listFiles();\n        for (int i = 0; i &lt; files.length; i++) {\n            System.out.println(files&#91;i].getName());\n        }\n        System.out.println(files&#91;1]);\n        System.out.println(files&#91;2]);\n\n        \/\/public File&#91;] listFiles():\u83b7\u53d6\u5f53\u524d\u76ee\u5f55\u4e0b\u6240\u6709\u7684\u4e00\u7ea7\u6587\u4ef6\u5bf9\u8c61\"\u5f97\u5230\u4e00\u4e2a\u6587\u4ef6\u5bf9\u8c61\u6570\u7ec4\u4e2d\u53bb\u8fd4\u56de\n        File&#91;] files1 = file.listFiles();\n        for(File f : files1){\n\n            System.out.println(f.getAbsolutePath());\/\/\u62ff\u5230\u7684\u662f\u7edd\u5bf9\u8def\u5f84\n\n\n        }\n    }\n}\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/note.ui11.cc\/wp-content\/uploads\/2024\/11\/image-152-1024x523.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"523\" data-original=\"https:\/\/note.ui11.cc\/wp-content\/uploads\/2024\/11\/image-152-1024x523.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-1581\"  sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/div><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u521b\u5efa\u6587\u4ef6\u548c\u5220\u9664\u6587\u4ef6\u7684\u5e38\u7528\u65b9\u6cd5\uff1a File\u5bf9\u8c61\u53ef\u4ee5\u5220\u9664\u4e00\u4e2a\u6587\u4ef6\uff0c\u6587\u4ef6\u5939\uff0c\u4e5f\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u6587\u4ef6\u4ee5\u53ca\u6587\u4ef6\u5939\uff0c\u53ef\u4ee5\u521b\u5efa\u591a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[],"class_list":["post-1574","post","type-post","status-publish","format-standard","hentry","category-fileio"],"_links":{"self":[{"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/posts\/1574","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/comments?post=1574"}],"version-history":[{"count":2,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/posts\/1574\/revisions"}],"predecessor-version":[{"id":1582,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/posts\/1574\/revisions\/1582"}],"wp:attachment":[{"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/media?parent=1574"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/categories?post=1574"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/tags?post=1574"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}