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
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
other's performance, which is pseudo-sharing. Write contention on cache lines is the most important limiting factor in the scalability of parallel threads running in SMP systems. Some people describe pseudo-sharing as a silent performance killer because it is hard to see whether pseudo-sharing occurs in the code.
In order for scalability to be linearly related to the number of threads, you must ensure that no two threads are written to the same v
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
(); output: 8b Fe 0
2> 0
0
43
/c21>
1.4 garbled problem The reason for the garbled problem is simple, because the encoding and decoding are inconsistent with the character coding. Such as: The above bytes3 byte data is a utf-16be format byte sequence, if decoding the time with utf-8 words, will appear garbled. String str1 = new String (BYTES3); System. out . pri
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
: Java 8 Adds the parameter name of the method to the byte code, so that the argument name can be obtained by reflection at run time only if the-parameters parameter is used at compile time.
Parallel (parallel) arrays: support for parallel processing of arrays, mainly the Pa
exception nullpointerexception. We use any object, we need to check whether this object is empty, we only execute the processing statement if the object is not empty.The optional class is like a container that holds a value of type or null value. By using the Ispresent () method of the optional class, we can check whether the specified object is empty.package demo.ch;import java.util.Optional;public class Java8OptionalDemo { public static void main(String[] args) { Optional4, StreamsT
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
()) {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
()
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
Concurrency boostStream in Java is similar to the idea of data analysis in Hadoop, except that Hadoop is large, using the computational ecology of multiple machines, while Java stream uses the process of analyzing a piece of data in a single computer with multiple CPUs. By using the Parrallel method to realize the parallel
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
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.