Today, the file creation problem is finally solved. That is to say, up to now, we have a preliminary understanding of the principle and structure of the file, because,
The file itself contains a lot of things. I believe that when I understand one of them, it will not be difficult for others to understand!
When creating a file,
If the file does not exist, the file is automatically created.
Import java. Io .*;
Public class dujian {
/**
* @ Param ARGs
*/
Public static void main (string [] ARGs ){
// Todo automatically generates method stubs
Try {
Fileinputstream = new fileinputstream (ARGs [0]);
// Open the file in this way.
Fileoutputstream = new fileoutputstream (ARGs [1]);
Byte [] buffer = new byte [1024];
While (true ){
If (fileinputstream. Available () <1024 ){
Int num =-1;
While (num = fileinputstream. Read ())! =-1 ){
Fileoutputstream. Write (Num );
}
Break;
}
Else
{
Fileinputstream. Read (buffer );
Fileoutputstream. Write (buffer );
}
Fileinputstream. Close ();
Fileoutputstream. Close ();
}
} Catch (arrayindexoutofboundsexception e ){
System. Out. Print ("meiyouzhidingwenjian ");}
Catch (ioexception e) {e. printstacktrace ();}
}
}