File class-casual

Source: Internet
Author: User
1 package IO; 2 3 Import Java. io. file; 4 Import Java. io. filenotfoundexception; 5 import Java. io. filereader; 6 Import Java. io. filewriter; 7 Import Java. io. filenamefilter; 8 Import Java. io. ioexception; 9 Import Java. io. reader; 10 Import Java. io. writer; 11 import Java. util. list; 12 13 public class file class {14 15/** read string output to TXT text 16 * @ Param ARGs 17 * @ throws ioexception 18 */19 public static void main (string [] ARGs) throws ioexception {20 // method 1 21 // file = new file ("D: \ new.txt "); 22 // Method 2: 23 // file file2 = new file ("D: \", "1.txt "); 24 // method 3: 25 // file file3 = new file ("d :\\"); 26 // file file4 = new file (file3, "1.txt "); 27 // These three methods have the same effect 28 29 // if a file exists, no 30 // file file2 = new file ("D: \ new \ a.txt "); 31 // system. out. println ("creatnewfile:" + file2.createnewfile (); 32 // create a folder, and return true if it already exists, false 33 // file = new file ("D: \ new1"); 34 // system. out. println ("mkdir:" + file. mkdir (); 35 36 // create a new folder at multiple levels. If a new folder exists, false is returned. 37 // file = new file ("D: \ newmu \ BBB "); 38 // system. out. println ("mkdirs:" + file. mkdirs (); 39 // delete a file without leaving the recycle bin 40 // file = new file ("D: \ 1.txt"); 41 // system. out. println ("filedelete:" + file. delete (); 42 // Delete the folder 43 // file = new file ("D: \ newmu \ BBB"); 44 // file. delete (); 45 // When deleting folders at multiple levels, you must first Delete the sub-layer file and folder 46 47 // file method. renameto (File file); if the path is the same, the renamed path is different, that is, the renamed + cut 48/* judgment function 49 * isdirectory () 50 * isfile () 51 * exists () 52 * Canread () 53 * canwrite () 54 * ishidder () 55 * getabsolutepath () 56 * getpath () 57 * getname () 58 * length () 59 * lastmodified () 60*61 * string list () return the name Array under the directory 62 * file [] listfiles () return the file array 63*64 */65 // file = new file ("D: \"); 66 // string [] list = file. list (); 67 // For (string S: List) {68 // system. out. println (s); 69 //} 70 71 // file = new file ("D: \"); 72 // file [] list = file. listfiles (); 73 // For (File S: List) {74 // system. out. println (S. getname () + "" + S. getabsolutepath (); 75 //} 76 // 77 // file name filter 78 // string [] list (filenamefilter filter) 79 // string [] listfiles (filenamefilter filter) 80 // output file 81 ending with TXT // file = new file ("D: \"); 82 // file [] list = file. listfiles (); 83 // For (file F: List) {84 // If (F. isfile () {85 // If (F. getname (). endswith (". TXT ") {86 // system. out. println (F. getname (); 87 //} 88 //} 89 // 90 //} 91 92 file = new file ("D :\\"); 93 string [] list = file. list (New filenamefilter () {94 95 @ override 96 public Boolean accept (File Dir, string name) {97 file = new file (Dir, name ); 98 // Boolean flag = file. isfile (); 99 // Boolean flag2 = Name. endswith (". TXT "); 100 // return flag & flag2; 101 return file. isfile () & name. endswith (". TXT "); 102} 103}); 104 for (string S: List) {105 system. out. println (s); 106} 107 108} 109 110}

 

File class-casual

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.