When creating a socket using the InputStream input stream, the read () method, if the call is available (), returns the length of the byte stream, may return 0, or other numeric values, often error in network operation, Because when you call the available () method, the data sent to the send may not yet arrive, and the count you get is 0. Network transmission is implemented as follows: intreadbytes=0;
[Java I/O] byte stream InputStream/OutputStream, inputstream byte streamByte stream InputStream/OutputStream
This article will give a brief summary of the byte stream InputStream/OutputStream in the java I/O Stream:
In general, ea
[Java Basics] InputStream, InputStreamReader, BufferedReader, inputstream, and reader
In Java, the above three classes are often used to process data streams. The following describes the differences between the three classes and their usage.
InputStream: A super class of
Original: Share a very useful Java program (key Code) (eight)---Java InputStream read the network response response data Method! ImportantJava InputStream Read Data problems======================================================================principle Explanation1. About Inputstream.read ()When reading data from a dat
Java. io. Reader and java. io. InputStream constitute Java input classes. Reader is used to read 16 characters, that is, Unicode-encoded characters. InputStream is used to readInput ASCII characters and binary data.In Java, differ
In Java, we often encounter the case of how to convert InputStream to string, such as getting a inputstream from a file or a network, which needs to be converted into a string output or assigned to another variable.The way I used to do this before really focusing on this problem was to read the buffer in bytes over and over, or to set up BufferedReader read-by-li
Note: Reference link: http://www.cnblogs.com/springcsc/archive/2009/12/03/1616187.html1, in Java stream represents a kind of data flow (source), Javaio of the underlying data element,----(imagined as a faucet)2. Any Javaio object capable of generating a data stream (source) can be regarded as a InputStream object since it can produce data, we can take the data out, Java
1, in Java stream represents a kind of data flow (source), Javaio of the underlying data element,----(imagined as a faucet)2. Any Javaio object capable of generating a data stream (source) can be viewed as a InputStream objectSince it produces data, we can take the data out, and the Java generic method of encapsulation is the read () method-(out of the faucet)3.
=========================================================================In the process of use, be sure to note that close () off each read-write stream!!!!!=========================================================================1. Convert file, FileInputStream to byte array:The "New file (parameter) parameter can write absolute path, or you can write a file name, this file will be generated in this directory of the project or from the root directory of this project to query whether there is th
default value is large enough.Therefore, it is recommended to use BufferedReader to wrap all of their read () operations with potentially expensive Reader (such as FileReader and InputStreamReader). For exampleBufferedReader in= new BufferedReader (New FileReader ("foo.in"));The input for the specified file is buffered.InputStreamReader (Java Platform SE 6)InputStreamReader is a bridge of byte flow to a character stream: it reads the bytes with the s
Original link: http://www.cnblogs.com/MyFavorite/archive/2010/10/19/1855758.html1. About Inputstream.read ()When reading data from a data stream, it is easy to use the Inputstream.read () method for diagrams. This method is to read one byte at a time from the stream and is very inefficient. A better approach is to read multiple bytes at a time using Inputstream.read (byte[] b) or Inputstream.read (byte[] B,int Off,int len) methods.2. Available () method for the
1. About Inputstream.read ()When reading data from a data stream, it is easy to use the Inputstream.read () method for diagrams. This method is to read one byte at a time from the stream and is very inefficient. A better approach is to read multiple bytes at a time using Inputstream.read (byte[] b) or Inputstream.read (byte[] B,int Off,int len) methods.2. Available () method for the InputStream classTo read more than one byte at a time, the Inputstrea
New people began to learn to write blog, do not like to spray. Welcome to the big guys to criticize, appreciate disrespect.
I did 10 months ago in C #, and later to the Java self-study also has a period of time, there is the basis of object-oriented learning is very fast. Today suddenly whim, want to operate the Java file read (have to say before they are very lazy, can Baidu things themselves do not want t
Summarize other answers I found one main ways to does this (see below). and I wrote some performance tests (see results below):Ways to convert an InputStream to a String:Using ioutils.tostring (Apache Utils)String result = ioutils.tostring (InputStream, standardcharsets.utf_8);Using Charstreams (Guava)String result = charstreams.tostring (New InputStreamReader (InputStr
Java IO (II)-InputStream, javaioinputstream
The source code uses JDK1.8 as a reference.
Preface: InputStream implements two interfaces: Closeable and AutoCloseable: Closeable: introduced in JDK1.5, The Closeable interface has only one definition of the close () method:Public void close () throws IOException;Objects of classes that implement the Closeable interfa
The source code is JDK1.8 as referencePreface:The InputStream implements two interfaces closeable and autocloseable:Introduced in closeable:jdk1.5, there is only one definition of the close () method in the Closeable interface:public void Close () throws IOException;The object of the class that implements the Closeable interface can be closed, and the stream class implements the interface to achieve the purpose of closing the stream.Introduced in auto
When getting input streams in Java, it is sometimes necessary to stream the input into a string in order to get the content, and the following summarizes the way InputStream turns into stringMethod 1: Public String convertstreamtostring (InputStream is) {BufferedReader reader = new bufferedreader (new InputStreamReader (IS));StringBuilder sb = new StringBuilder (
There are several ways to read and write files in Java, where the following comparisons are made by code.Comparison one: FileWriter and FileReader Public classMyCode1 { Public Static voidMain (string[] args) throws IOException {File F=NewFile ("My.txt"); FileWriter FW=NewFileWriter (f); Fw.write ("HELLO"); Fw.close (); FileReader FR=NewFileReader (f); System. out. println (Char) Fr.read ()); Fr.close (); }}Output:
Use of inputstream in java
Inputstream in java is a byte-oriented stream abstract class. It derives various classes based on specific applications.
For example, FileInputStream is an object that inherits from InputStream and is used to read file streams. Its specific inherit
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.