The API object that is able to read the sequence of bytes is the input stream (InputStream), which is the output stream (OutputStream) that can be written into the sequence of bytes. Bytes are the stored form of computer data, and any data can be read and written using a byte stream.
Read source and write target can be file, memory, network, database and file.
InputStream and OutputStream two abstract classes form the framework foundation of the read/write IO system.
Although the byte stream can manipulate any form of data, it is not very convenient for characters that occupy multiple bytes, so there are two abstract classes of reader and writer that are specifically provided for character streams in Java.
Classification:
Io stream by operand: byte stream and character stream
By direction of flow: input stream and output stream
System diagram of the main stream: each input stream has a corresponding output stream
After the abstract class Input/outputstream Readerwriter followed by the specific implementation subclass
Character Stream
Character stream is mainly for the processing of text content is very convenient to read and write, according to the character input and output and byte stream operation is not different, but the read and write operation unit is no longer a byte.
Get information about a file
It is known that there are two files under the current directory and can read its information using the API of the file object.
Query out file size, name, absolute path, parent directory, last modified time, whether to hide file
Warning: Mysterious hidden movies and selfies in the xxx disk are the fruit dew in front of the program.
Take a look at some of the common methods of file objects :
|
Role |
function signature |
Practical Grade |
|
Get file name |
String GetName () |
***** |
|
Whether the disk file exists |
Boolean exists () |
***** |
|
Get the disk absolute address of the file |
String GetAbsolutePath () |
***** |
|
List of files under the column-fetching folder
With filters
There is a file name filter
File must be a folder to use |
File[] Listfiles ()
File[] Listfiles (filefilter filter)
File[] Listfiles (filenamefilter filter)
|
*****
|
|
Create a folder |
Boolean mkdir () |
***** |
|
Create a file
Specify a file in the directory where the specified prefix and suffix are created |
Boolean CreateNewFile ()
Createtempfile (string prefix, string suffix, File directory) |
***** |
|
Get Parent Directory
|
String getParent ()//upper file path
File Getparentfile ()//top-level files |
***** |
|
Whether to hide |
Boolean Ishidden () |
***** |
|
deleting files |
Boolean Delete () |
***** |
There are other ways to do this: such as determining whether the "executable method", "readable", "writable", and so on permissions files, more see the JDKAPI documentation.
Java IO stream