Let's talk about Java I/O, java
In java, I/O operations are classified into two categories at the macro level. One isByte stream,One is the upstream stream, which corresponds to a group of classes and interfaces respectively.
Byte stream:
Base class of InputStream input stream
Base class of OutputStream output stream
For byte streams, these two classes are the most basic classes.
Ghost stream:
Reader input stream base class
Base class of Writer output stream
It corresponds to two base classes in the byte stream, and the byte stream also has two closest classes.
There are two adapter classes in the sequence stream class group, which are used to convert byte streams into inverted streams, that is, converting from InputStream to Inverted Reader from OutputStream to Inverted Writer
They are:
InputStreamReader
OutputStreamWriter
In the programming process, whether the use of the byte stream or the byte stream needs to be determined based on the actual situation.
Java I/o Problems
DataOutputStream out = new DataOutputStream (
New FileOutputStream ("test. dat "));
DataInputStream in = new DataInputStream (
// ********** Found **********
New FileInputStream ("(" test. dat "));
In. closed ();
Java I/O Problems
Import java. io. DataOutputStream;
Import java. io. File;
Import java. io. FileOutputStream;
Import java. io. IOException;
Public class IO {
Public static void main (String args []) {
// Raw data
Double [] nums = {2.23, 4.67, 6.54, 2.22, 1.45, 5.64 };
// Save the data to the current folder named save. dat.
File file = new File (System. getProperty ("user. dir") + "\ save. dat ");
FileOutputStream fos = null;
DataOutputStream dos = null;
Try {
// If the object does not exist, create a new object.
If (! File. exists ())
File. createNewFile ();
// Create File streams and data streams
Fos = new FileOutputStream (file );
Dos = new DataOutputStream (fos );
// Write data
For (int I = 0; I <nums. length; I ++ ){
Dos. writeDouble (nums [I]);
}
} Catch (IOException e ){
E. printStackTrace ();
} Finally {
// The operation ends. Close two streams.
Try {
If (dos! = Null)
Dos. close ();
If (fos! = Null)
Fos. close ();
} Catch (IOException e ){
E. printStackTrace ();
}
}
}
}