File class:
Common methods:
Boolean exists (): Determines whether a file or directory exists
boolean isfile (): Determines whether the file is
boolean isdirectory (): Determines whether the directory
String GetPath (): returns the relative path name of the file represented by this object
String GetAbsolutePath (): Returns the absolute path name of the file represented by this object
String getName (): Returns the name of the file or directory represented by this object
Boolean Delete (): Deletes the file or directory specified by this object
boolean createnewfile (): Create a name for an empty file without creating a folder
long Length (): Returns the length of the file, in bytes, or 0L if the file does not exist
I/O flow
Classification of streams:
According to the direction of flow:
Output streams:outputstream and Writer as base classes
Input stream:inputstream and Reader as base classes
According to the Processing Data Unit Division:
BYTE stream:
BYTE output stream:outputstream base class
BYTE input stream:InputStream base class
Character Stream:
Character output stream:Writer base class
Character input stream:Reader base class
Cases:
1, create the input stream object, responsible for reading d:\ my youth who decides. txt file
FileInputStream fis = new FileInputStream ("d:\\ my youth who decides. txt");
2. Create an output stream object, responsible for writing the contents of the file to C:\myFile\my Prime.txt
FileOutputStream fos = new FileOutputStream ("C:\\myfile\\myprime.txt", true);
3. Create a broker array to hold the contents of each read
byte words [] = new char[1024];
4, through the loop to achieve file read and write
while ((Fis.read ())!=-1) {
Fis.read (words); Read file
Fos.write (words, 0, words.length); Write file
}
Java File I/O