{"id":933,"date":"2018-09-17T18:35:38","date_gmt":"2018-09-17T09:35:38","guid":{"rendered":"https:\/\/chat-messenger.com\/?p=933"},"modified":"2018-12-23T01:56:42","modified_gmt":"2018-12-22T16:56:42","slug":"file-listfiles","status":"publish","type":"post","link":"https:\/\/chat-messenger.com\/en\/blog\/java\/file-listfiles","title":{"rendered":"Displays a list of files in the Java directory"},"content":{"rendered":"<h2 class=\"common_title\"><a name=\"0\"><strong>Java<\/strong><strong>directory<\/strong>within<strong>File List<\/strong>Displaying File.listFiles()<\/a><\/h2>\n<p>\n<strong>Java<\/strong>and the specified<strong>directory<\/strong>within<strong>File List<\/strong>Here is a sample program that displays<br \/>\n<strong>File List<\/strong>To display the <strong>java.io.File<\/strong> The following methods of the class are used\n<\/p>\n<div class=\"point\">\n<ul>\n<li><strong>list()<\/strong>... lists the files and directories contained in the specified directory. <u>Array of String type<\/u>Return by<\/li>\n<li><strong>listFiles()<\/strong>... lists the files and directories contained in the specified directory. <u>Array of File type<\/u>Return by<\/li>\n<\/ul>\n<\/div>\n<p><script type=\"text\/javascript\" src=\"https:\/\/chat-messenger.com\/js\/common.js?dd12sssas2223\" charset=\"UTF-8\"><\/script><br \/>\n<script type=\"text\/javascript\"> writePR(); <\/script><\/p>\n<h2 class=\"common_title\"><a name=\"1\">sample program<\/a><\/h2>\n<p>To check the sample program, we created a filelist directory and prepared the following files.<\/p>\n<pre class=\"console\">C:\\filelist\r\n    \u2502 aaa.java\r\n    \u2502 bbb.java\r\n    \u2514\u2500dir\r\n           ccc.java\r\n           ddd.java\r\n           eee.jpg\r\n<\/pre>\n\n<pre class=\"sample_src\">public static void main(String[] args) {\r\n    String path = \"C:\\filelist\";\r\n    File dir = new File(path);\r\n    File[] files = dir.listFiles();\r\n    for (int i = 0; i &lt; files.length; i++) {\r\n        File file = files[i];\r\n        System.out.println((i + 1) + &quot;: &quot; + file);\r\n    }\r\n}\r\n<\/pre>\n<h2 class=\"common_title\"><a name=\"2\">Execution Result<\/a><\/h2>\n<p>\u25c6Output result<\/p>\n<pre class=\"console\">1: C:\\filelist\\aaa.java\r\n2: C:\\filelist\\bbb.java\r\n3: C:\\filelist\\dir\r\n<\/pre>\n<p>You were able to display a list of files and directories contained in \"C:\\filelist\".<br \/>\nHowever, the list of files contained under \"C:\\filelist\\dir\" is not displayed.<\/p>\n<p><strong>java.io.File<\/strong> Class <strong>list()<\/strong>, ,<strong>listFiles()<\/strong> both do not seem to show up to subdirectory listings.<br \/>\nNext, we will introduce a program that easily displays and searches a list of files and directories, including subdirectories, through recursive processing.<br \/>\n<a href=\"https:\/\/chat-messenger.com\/en\/blog\/java\/filesearch\/\"><strong>java Recursively search for files<\/strong><\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>Display a list of files in the Java directory. File.listFiles() in Java, specified directory [\u2026]<\/p>","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":""},"categories":[19],"tags":[],"_links":{"self":[{"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/posts\/933"}],"collection":[{"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/comments?post=933"}],"version-history":[{"count":7,"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/posts\/933\/revisions"}],"predecessor-version":[{"id":1888,"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/posts\/933\/revisions\/1888"}],"wp:attachment":[{"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/media?parent=933"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/categories?post=933"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/tags?post=933"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}