Java learning notes-basic methods of the File class, java learning notes-file

Source: Internet
Author: User

Java learning notes-basic methods of the File class, java learning notes-file

Gradually develop the habit of writing blogs -----"

Some time ago, I/O stream in the java of Mars was not fully understood, and it was difficult to find the I/O Stream. Today, I read other teaching courses, books, and notes to record my daily study and life.

File class methods:

1 package com. cnblogs; 2 3 import java. io. file; 4 import java. io. IOException; 5 6 public class FileTest {7 public static void main (String [] args) throws IOException {8 File file File = new File ("F:" + File. separator + "temp" + File. separator + "a.txt"); 9 // determine whether the directory is 10 System. out. println (file. isDirectory (); 11 // determine whether the file is 12 System. out. println (file. isFile (); 13 // create a new file 14 file. createNewFile (); 15 System. out. println (file. isFile (); 16 System. out. println (file. isDirectory (); 17 // determines whether the System is readable. out. println (file. canRead (); 19 // judge whether the System can be written 20. out. println (file. canWrite (); 21 // get the length 22 System. out. println (file. length (); 23 // obtain the path strength 24 System. out. println (file. getPath (); 25 // get the file parent directory 26 System. out. println (file. getParentFile (); 27 // get the separator 28 System. out. println (file. pathSeparator); 29 System. out. println (file. separator); 30} 31 public static void main2 (String [] args) throws IOException {32 File file = new File ("F:" + File. separator + "temp" + File. separator + "a.txt"); 33 // judge whether the file exists 34 if (file. exists () {35 file. renameTo (new File ("F:" + File. separator + "temp" + File. separator + "B .txt"); 36} 37 // if the above does not exist, create a new file 38 else {39 file. createNewFile (); 40} 41 42} 43}


 

 

  

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.