Java reads the files in the fixed directory (almost the same as the previous article)

Source: Internet
Author: User

Package Gao.org;import Java.io.filenotfoundexception;import Java.io.ioexception;import Java.io.File;public class ReadFile {public ReadFile () {}/** * reads all files under a directory */public static Boolean R  Eadfile (String filepath) throws FileNotFoundException, IOException {try {file file                        = new File (filepath);                                if (!file.isdirectory ()) {System.out.println ("file");                                System.out.println ("path=" + File.getpath ());                                System.out.println ("absolutepath=" + File.getabsolutepath ());                        System.out.println ("name=" + file.getname ());                                } else if (File.isdirectory ()) {System.out.println ("directory");                                string[] filelist = File.list ();            for (int i = 0; i < filelist.length; i++) {                            File ReadFile = new file (filepath + "\ \" + filelist[i]); if (!readfile.isdirectory ()) {System.out.println ("path=" + readfile.get                                                Path ()); System.out.println ("absolutepath=" + Readfile.getabsolutepa                                                th ());                                        System.out.println ("name=" + readfile.getname ()); } else if (Readfile.isdirectory ()) {ReadFile (filepath + "\ \" + Filelist[i]                                        );                        }}}} catch (FileNotFoundException e) {                System.out.println ("ReadFile () Exception:" + e.getmessage ());        } return true; }        /**         * Delete all directories and files under a directory *//*public static Boolean DeleteFile (String delpath)                        Throws FileNotFoundException, IOException {try {File file = new file (Delpath);                                if (!file.isdirectory ()) {System.out.println ("1");                        File.delete ();                                } else if (File.isdirectory ()) {System.out.println ("2");                                string[] filelist = File.list (); for (int i = 0; i < filelist.length; i++) {File Delfile = new File (Delpath + "\                                        \ "+ filelist[i]); if (!delfile.isdirectory ()) {System.out.println ("path=" + delfile.getpath (                                                ));          System.out.println ("Absolutepath="                                                      + Delfile.getabsolutepath ());                                                System.out.println ("name=" + delfile.getname ());                                                Delfile.delete ();                                        System.out.println ("Delete file succeeded"); } else if (Delfile.isdirectory ()) {DeleteFile (delpath + "\ \" + Filelist[i]                                        );                        }} file.delete ();  }} catch (FileNotFoundException e) {System.out.println ("DeleteFile () Exception:"                + e.getmessage ());        } return true;                        }*/public static void Main (string[] args) {try {//can change the following path ReadFile ("d:\\users\\gao\\desktop\\bionlp2013data\\develop ");                DeleteFile ("D:/file"); } catch (FileNotFoundException ex) {} catch (IOException ex) {} System.out.        println ("OK"); }}

Java reads the files in the fixed directory (almost the same as the previous article)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.