Review the file class of Javaio

Source: Internet
Author: User

The file class is the only class in the IO package that represents the information for the disk file itself, not the contents of the files

The file class defines some platform-independent methods to manipulate files,

Directories in Java are used as a special type of file, and the list method can return all subdirectories and filenames in the directory

The path delimiter under UNIX is (/), the path delimiter under DOS is (\), and Java can correctly handle both path separators

Demo

Determines whether a file exists, is deleted, does not exist, and creates

Code Snippets

File F = new file ("1.txt");

if (f.exists ()) {

F.delete ();

}else{

F.createnewfile ();

}

System.out.println ("File name" +f.getname ()); Get the file name

System.out.println ("File path" +f.getpath ()); Get file relative path (path includes file name)

System.out.println ("File ASB Path" +f.getabsolutepath ()); Get the file absolute path

System.out.println (F.exists ()? " Exists ":" Not Exists "); Determine if a file exists

System.out.println (F.canread ()? " Read ":" not read "); Determine if a file is readable

System.out.println (F.isdirectory ()? " Directory ":" Not being directory "); Determine if a file is a directory

System.out.println ("Filed last Modifield Time" +f.lastmodifield ());//File Latest modified

System.out.println ("File name" +f.getname ()); Get the file name

Review the file class of Javaio

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.