Io flow is used to process data transfer between devices
The Java operation of the data is streamed through the way
The objects that Java uses to manipulate the flow are in the IO Package
There are two types of flow by operation data: byte stream and character stream
Flow is divided into: input stream, output stream
Character Stream
Abstract base class:Reader Writer
File operations, writing
Gets the FileWriter object,new , constructs the parameter: The file name of the String, and, if it already exists, creates it under the specified directory. will be overwritten; This method throws a ioexception Exception
Call the write () method of the FileWriter object to write the string to the stream, parameter: string
Call the flush () method of the FileWriter object to flush the stream
FileWriter fw=New FileWriter ("test.txt"); Fw.write ("Hello3"); Fw.close (); // Refresh and Close
File operation, read
Gets the filereader object,new , constructs the parameter: The file name of the String
Call the Read () method of the filereader object , return the length of the reading, or 1, if it returns to the end of theparameter: char[] character array
while loop read, condition: If the length of the read is not -1
Combining strings
FileReader fr=New filereader ("test.txt"); Char [] buf=newchar[2]; int len=0; StringBuilder SB=new StringBuilder (); while ((Len=fr.read (BUF))!=-1) { sb.append (new String (buf,0, Len)); } System.out.println (Sb.tostring ());
PHP version, file operation, write
Call the function fopen (), open the file to obtain the file object, parameter:String filename,"W" Write is created if the file does not exist
Call the fwrite () method and write it directly to the file, parameter: string
Call the fclose () method to close the stream, parameter:file object
$file=fopen("Test.txt", "W"); fwrite ($file, "Hello"); fclose ($file);
File operation, read
calling Functions fopen () , open file Get file object, Parameters: String the file name, "R" Read
Call function fread (), get string strings, arguments:file object, read length
while loop read, condition: No to end of file,feof ($file) not true
Stitching strings
$file=fopen("Test.txt", "R"); $str= ""; while (! feof ($file)) { $str. =fread($file, 1);} Echo $str ; fclose ($file);
The above describes [PHP] back to the basics (IO stream), including PHP, the basic aspects of the content, I hope that the PHP tutorial interested in a friend helpful.