The 1.File class is used to encapsulate files or folders into objects
Facilitates the operation of file shelf property information
The file object can be passed as a parameter to the stream's constructor
Encapsulate an existing or non-appearing file or folder as an object
The file class has a static property, separator, that represents the system-related directory delimiter, expressed as a string
Common methods for 2.File classes
1. Create
Boolen CreateNewFile (): Creates a file at the specified location, if the file already exists, does not create, returns false
Unlike the output stream, the output stream object is created to create the file, and if the file exists, it overwrites
Boolean createtempfile (): Create temporary file
boolean mkdir () Create Folder
Boolean madirs (): Create a multilevel directory
2. Delete
Boolean Delete () if the file does not exist put back false
boolean Deleteonexit (): Deletes the specified file
when the program exits;
3. Judgment
// In determining whether a file object is a document or a directory, you must first determine if file exists
Boolean exists (): Whether the files exist
isfile ()
isdirectory ()
Ishidden ( Whether to hide
isabsolute () is an absolute path
4. Get information
getName ()
GetPath ()
getParent (): The method returns the parent directory in the absolute path, and returns null
if a relative path is obtained GetAbsolutePath ()
lastmodified ()
length ()
5.renameTo (File f): Rename or cut action can be done
Listroots (): Static method, returns a file array, lists the files that are available in the root system
List (): Returns a string array that lists the names of all files or folders under the specified directory, and returns NULL if the specified directory is a file, and the specified directory must exist
List (filenamefilter filer): Filter based on file name filtering, based on the accept (file Dir,string name) method return value
Listfiles (): Returns the file array,
Listfiles (FilenameFilter filter)
5.Properities is a subclass of Hashtable
That is, it has the characteristics of the map set, and the stored key values are all strings.
is a collection container combined with IO technology
Characteristics of the object: a configuration file that can be used in the form of a key-value pair
There are two methods setproperty (keys, values) and GetProperty (keys), which are used to get the properties of a good setting property
Other classes in the 6.IO package:
Print Flow: Provides a printing method that can print data of various data types in a Mandarin duck
byte print stream printstream
parameter types that the constructor can accept:
(1) File object file
(2) string path
(3) byte output stream OutputStream
Character Print stream PrintWriter
parameter types that the constructor can accept:
(1) File Object file
(2) String path
(3) Byte output stream OutputStream
(4) Character output stream: Writer
2.SequenceInputStream (tandem Flow)
Used to write data from multiple streams into a stream, the constructor is passed into the enumeration< Extends inpustream>
Vector or custom enumeration class is required, and EN is passed to Sequenceinputstream's constructor
Final iterator<fileinputstream> it=arr.iterator ();
Enumeration<fileinputstream> en=new enumeration<fileinputstream> () {
@Override
public boolean hasmoreelements () {
return It.hasnext ();
}
Public FileInputStream nextelement () {
return It.next ();
}
}
Dark Horse Programmer--file Class