About input and output streams Notes:
Master the following basic syntax:
- Read byte by byte
a) reading a byte only
InputStream in = new InputStream(“xxx”);
Int i = In.read (); // read a byte hash value is returned
b) reading all the bytes
InputStream in = new InputStream(“xxx”);
Int s;
While ((s = in.read) = -! 1) {// if in.read () -1 result indicates the last byte has been read
Sysotem.out.print (s); // returns the value of the equation on the left
}
2. Byte stream read data buffer
c) byte[ ] b = new byte[ length];
int len;
the while (! (len = in.read (B)) = -. 1) {//in.read(b): Reads the specified length of bytes of data to the array
. The System OUT .write (B, 0, len); // output array, and a predetermined length of the output array
}
Several forms of output:
1.System.out.print (xxx); the output stream of bytes
2.System.out.write (xxx, ....); Output is a character stream
3.out.write (xxx); folder output to the output stream
Removal of the file:
For a single file, () method removes a xxx.delete, for non-empty folder, judgment needs to be non-empty, only delete empty folder, reference to the following specific method:
. 1 public static Boolean del (File F) { 2 . 3 // For folders, need to obtain all the files in the folder . 4 . 5 IF (f.isDirectory ()) { . 6 . 7 File [] FS = f.listFiles (); . 8 9 // empty folder 10 . 11 IF (FS == null || fs.length == 0 ) { 12 is 13 is return f.delete (); 14 15 } the else { 16 . 17 for (file file: FS) { 18 is . 19 del (file);// recursive call 20 is 21 is } 22 is 23 is } 24 25 } 26 is 27 // For non folder can delete 28 29 return f.delete (); 30 31 is }