After reading the stream, the server returns some data to the client, telling the client that it has finished writing.Similar to the "stream operation-write action after getting the source", the client also reads byte and buffered two buffers as an example, and. I hope you will give us a supplement.1. Using OutputStream to write back to the client, the client uses byte as the buffer to receiveWrite back to
() overloaded method to format the output directly. However, when formatting the output, you need to specify the format of the output data type.PrintWriter: is a character print stream.The constructor can receive four types of values.1, string path.The 2,file object.You can also specify an encoding table for data of type. That is, the character set.3,outputstream4,writerfor data of type 3,4, you can specify automatic refresh.Note: When this auto-refresh value is True, only three methods can be
1.4 ways to copy a picture case:Analysis:Copy the data, if we know to open with Notepad and can read, use a character stream, otherwise with the word stream.By this principle, we know that we should adopt a byte stream.There are 4 ways to do this, so we have 4 ways of doing this. Recommended to master the 4th kind.Data Source :C:\\a.jpg--FileInputStream--BufferedinputstreamDestination :D:\\b.jpg--FileOutputStream--Bufferedoutputstream2. 4 ways code E
1.File only operates on the file itself, and if you want to manipulate its content, you need to use the Randomaccessfile class. (You need to receive the file class object, then proceed, remember closing close)2. You can use byte stream (InputStream OutputStream) and character stream (Writer Reader) when no random access is required.3. File operation process:Open a file using the file class;The output loca
()) {File.createnewfile (); } Randomaccessfile RAF=NewRandomaccessfile (file, "RW"); System.out.println (Raf.getfilepointer ()); Raf.write (' A ');//One char takes two bytes, but write writes only one byte at a time (the last eight bits of the A character)System.out.println (Raf.getfilepointer ()); Raf.write (B); inti = 0x7fffffff; Raf.write (i>>> 24);//write high eight bits of IRaf.write (i >>> 16); Raf.write (i>> 8); Ra
The streams provided by the JDK inherit four classes: InputStream (byte input stream), OutputStream (byte output stream), Reader (character input stream), Writer (character output stream).the main differences between character streams and byte streams are: 1. When the byte stream
:
The server's connection to the client is equivalent to 1:1, so if the number of connections goes up, the pressure on the servers will be great.
If the main thread acceptor blocked, then the entire server will be blocked, a single point of serious
When the number of threads expands, the performance of the entire server drops
The improvements can be based on the thread pool or Message Queuing , but there are some problems:
The number of thread pools, the number of
IO stream library, the new IO stream is often more layered. Likewise, this is a disadvantage of the adorner scheme-the need to pay for additional flexibility.The most important reason for adding reader and writer levels to Java 1.1 is the need for internationalization. The old IO flow hierarchy supports only 8-bit byt
accurately.We should not encapsulate the above auxiliary "functions" in the Io stream object, because doing so will allow the IO stream to take care of the operations of other types of logic outside the responsibility of reading and writing data. Therefore, in the Java IO class, there is also a class that is responsible for "optimizing the IO
{Pipedoutputstream out;Static int COUNT = 0; // record the number of threadsInt K = 0;Public send (pipedoutputstream out, int K){This. Out = out;This. k = K;This. Count ++; // The number of threads plus 1}Public void run (){System. Out. Print ("/R/nsend" + this. K + ":" + this. getname () + "");Int I = K;Try{While (I {Out. Write (I );I + = 2;Sleep (1 );}If (send. Count = 1) // when only one thread is left{Out. Close (); // close the input pipeline streamSystem. Out. println ("out closed! ");}Els
{Pipedoutputstream out;Static int COUNT = 0; // record the number of threadsInt K = 0;Public send (pipedoutputstream out, int K){This. Out = out;This. k = K;This. Count ++; // The number of threads plus 1}Public void run (){System. Out. Print ("/R/nsend" + this. K + ":" + this. getname () + "");Int I = K;Try{While (I {Out. Write (I );I + = 2;Sleep (1 );}If (send. Count = 1) // when only one thread is left{Out. Close (); // close the input pipeline streamSystem. Out. println ("out closed! ");}Els
create a file object specifying an abstract path nameTenFile File =NewFile ("E:"); One //get all content in the specified directory (file array) Afile[] Files =file.listfiles (); - //iterate through the array and determine if the condition is met - for(File f:files) { the if(F.isfile ()) { - if(F.getname (). EndsWith (". jpg")){ - System.out.println (F.getname ()); - } + } - } + } A}1 Packagecn.itcast_
Click " programmer Big Coffee " above, select "Public number"
Critical moment, first time delivery.
Some changes have been made to the concurrent packages in Java 8 and Java 9, and the changes are summarized in this article.
changes in Concurrent package in Java 8
new c
File ClassUsed to encapsulate a file or directory as an objectFacilitates processing of file or directory informationThe file object can be passed as a parameter to the stream for manipulationCommon methods of File classCreatebooleancreateNewFile():创建新文件,如果文件存在,返回falsebooleanmkdir():创建目录,只能创建一级目录booleanmkdirs():创建目录,可创建多级目录Deletebooleandelete():删除文件,如果文件不存在,返回false,如果删除的是目录,需要确保目录是空的voiddeleteOnExit():程序结束时删除文件Judgingbooleanexists():判断文件是否存在booleanisF
Lambda expression corresponds to the abstract method in the functional interface.In addition, Java 8 allows us to add a non-abstract method implementation to the interface. We only need to use the default keyword. This feature is also called an extension method ,. Therefore, function interfaces can only have one abstract method, while others can only be extension methods. The following is the Comparator in
1. Overview of propertiesProperties: Property Collection Class . is a collection class that can be used in conjunction with IO streams. Properties can be saved in a stream or loaded from a stream. each key and its corresponding value in the property list is a string .Properties is a subclass of Hashtable , and the description is a map collection .2. Properties as a map collection using1 Packagecn.itcast_08
()
Close Stream Object
Java.io.OutputStreamWriter
Public String getencoding ()
Returns the character encoding name used by the stream
Simple example: Save "Hello World" to a file. A string that does not exist when the file is created, overwriting The original file content when the file exists. 1 FileWriter fw = new FileWriter (" Ioflow.txt " 2 fw.wr
Java IO stream technology-File, javaio
IO stream technology
Concept: input-output:
Input: Read the file to the memory;
Output: write files from memory to other places
Role: mainly solves the problem of data transmission between devices.
File: The use of file classes is very important.
(1) file Construction Method
1 public static void test1 () {2 3 // three splici
longer readwhile ((N=fis.read (words))!=-1) {//6. Read the information in the file input stream until-1 endsFos.write (Words,0,n); 7. The file output stream is written to read the content length in the words array is 0-n}System.out.print ("File copy succeeded, view file");}catch (Filenotfoundexcepton e) {//The first input file may not be found here to write an exceptionE.prinntstacktrace (); Exceptions fro
read (). When there is no resource, it will be blocked and almost no resource is occupied.The close () method is not redundant for JAVA garbage collectors, because when an InputStream object is created, some resources will be generated in the operating system, but the garbage collector can only recycle object garbage.
4. OutputStream classThree write () methods.Flush () writes data to the buffer immediatelyClose () writes data to the buffer and close
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service