File

package cm;

import java.io.File;
import java.io.IOException;

public class test20180422File {

	public static void main(String[] args) throws IOException {
		// Objects of this class are abstract representations of file and directory pathnames.
		P.sopl(File.pathSeparator);//System-related path separator, string type
		System.out.println(File.pathSeparatorChar);//System-related path separator, char type
		P.sopl(File.separator);//System-related name separator.
		
		//4 constructors
		//1.File(File parent,String child) creates a new File instance based on the parent abstract pathname and child pathname string.
		//2.File(String pathname) Creates a new File instance by converting the given pathname string to an abstract pathname.
        //3.File(String parent, String child) creates a new File instance based on the parent pathname string and the child pathname string.
		//4.File(URI uri) Creates a new File instance by converting the given file: URI to an abstract pathname.
		
		File f=new File("D:\\a.txt");
		File f2=new File("F:\\好压\\Haozip\\Haozip.exe");
		P.sopl(f.canExecute()+"");//true
		P.sopl(f2.canExecute()+"");//Check if executable//true
		
		P.sopl(f.canRead()+"");//true
		P.sopl(f2.canRead()+"");//Check if executable//true
		
		P.sopl(f.canWrite()+"");//Check if writable//true
		P.sopl(f2.canWrite()+"");//Check if writable//true
		
		P.sopl(f.compareTo(f2)+"");//Compare two abstract path names in alphabetical order
		
		P.sopl(f.createNewFile()+"");//Whether the abstract object can create the corresponding file, if it does not exist, create it, return true, otherwise return false.
		
		P.sopl(File.createTempFile("bigsea", ".lol")+"");//Create a file with a prefix of bigsea and a suffix of .lol in the default temporary directory.
		
		//P.sopl(f.delete()+"");//Delete the file or directory represented by the abstract pathname.
		
		f.deleteOnExit();//Delete this file when the virtual machine is terminated.
		
		f.equals(f2);//Test whether this abstract path name is equal to the given path.
		
		f.exists();//Determine whether the file or directory represented by this abstract pathname exists.
		
		P.sopl(f.getAbsolutePath());//Return the absolute path name.
		
		P.sopl(f.getFreeSpace()+"");//Returns the number of unallocated bytes in the partition specified by this abstract pathname.
		
		P.sopl(f.getName()+"");//Returns the name of the file or directory represented by this abstract pathname.
		
		P.sopl(f.getParent());//Returns the pathname string of the parent directory of this abstract pathname; if this pathname does not specify a parent directory, it returns null.
		
		P.sopl(f.getPath());//Convert this abstract pathname to a pathname string.
		
		System.out.println(f.getTotalSpace());//Returns the partition size specified by this abstract pathname.
		
		f.hashCode();//long Calculate the hash code of the path.
		
		f.isAbsolute();//boolean is the absolute path
		
		f.isDirectory();//boolean is a directory
		
		f.isFile();//boolean is a file. A file is a standard file if it is not a directory and meets other system-related criteria. All non-directory files created by Java applications must be standard files.
		
		f.isHidden();//boolean can be hidden.
		
		f.lastModified();//long The last modified time is a timestamp.
		 
		f.length();//The length of the file represented by long.
		
		f.list();//Returns an array of strings specifying the files and directories in the directory represented by this abstract pathname.
		
		//f.mkdir(); Create the directory specified by this abstract pathname.
		
		f.mkdirs(); //Create the directory specified by this abstract pathname, including all required but nonexistent parent directories.
		
		f.renameTo(f2);//Rename the file represented by this abstract pathname.
		
		f.setExecutable(false);//Convenience method that gives the owner the execution mode.
		
		//f.setLastModified(time)//Set the modification time.
		
		//f.setReadable(boolean readable); A convenience method to set the read permission of the owner of this abstract pathname.
		
		f.setReadOnly();//Set as read-only.
		
		//f.setWritable(boolean writable)/ A convenience method to set the write permission of the owner of this abstract pathname.
		
	}

}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324621841&siteId=291194637
Recommended