Discover datainputstream readfully, include the articles, news, trends, analysis and practical advice about datainputstream readfully on alibabacloud.com
: This article mainly introduces the connection between PHPsocket implementation and Java readFully. if you are interested in PHP tutorials, please refer to it. Java:
DataInputStream stream = new DataInputStream (new BufferedInputStream (socket. getInputStream (); int I = stream. readInt (); byte [] B = newbyte [I]; stream.
DataInputStreamDataInputStream is the data input stream. It inherits from FilterInputStream.DataInputStream is used to decorate other input streams, which "allows applications to read basic Java data types from the underlying input stream in a machine-independent manner." Applications can use DataOutputStream (data output streams) to write data that is read by the DataInputStream (data input stream).DataInputStrea
1. Basic Concepts DataOutputStream data output stream allows applications to write Basic Java data types to the output stream in an appropriate way. Then the application can use the data input stream to read data. The DataOutputStream data input stream allows applications to read Basic Java data types from the underlying input stream in a machine-independent manner. Applications can use the data output stream to write data that is later read by the data input stream. Multi-threaded access is not
readfully
readfully (byte[] b)
Throws IOExceptionReads some bytes from a input stream and stores them into the buffer array B. The number of bytes read is equal to the length of B.
This method blocks until one of the following conditions occurs:
B.length bytes of input data is available, with which case a normal return is made. End of file is detected, in which case an eofexception is thrown
);//Writes a string to the basic output stream in a machine-independent way with the UTF-8 revision. The method first writes two bytes with Writeshort to indicate the number of bytes later.
int size ();//Returns the current value of written
DataInputStream allows applications to read basic Java data types from the underlying input stream in a machine-independent manner. Applications can use data output streams to write data that is read by th
ImportJava.io.BufferedInputStream;ImportJava.io.BufferedOutputStream;ImportJava.io.ByteArrayInputStream;ImportJava.io.ByteArrayOutputStream;ImportJava.io.DataInputStream;ImportJava.io.DataOutputStream;ImportJava.io.FileInputStream;ImportJava.io.FileOutputStream;Importjava.io.IOException; Public classDataStream { Public Static voidMain (string[] args)throwsIOException {//Write ("Test5.txt");//Read ("Test5.txt");Readfrombuffer (Writetobuffer ()); } //write to local file Public Static vo
will only write after 8 bits * dataout The Writeint * method of the Putstream Dos object must be written 4 times per write using the Write method of the Out object * Writeint internal must be * Out.write (10000>>24) * Out.write (10000>>16) * Out.write (10000>>8) * Out.write (10000) */ Dos.writeint (+); Dos.writeboolean (TRUE); Dos.writedouble (10.03); Dos.writeutf ("HelloWorld"); Dos.close (); } catch (Exception e) { E.printstacktrace (); } } public static void Read () {try {
Dataoutputstream dos = new dataoutputstream (New bufferedoutputstream (New fileoutputstream ("a.txt"); dos. writeint (5); dos. writeboolean (true); dos. flush (); dos. close (); datainputstream Dis = new datainputstream (New bufferedinputstream (New fileinputstream ("a.txt"); system. out. println (DIS. readint (); system. out. println (DIS. readboolean (); DIS. close (); // learn how to close the stream buf
Both datainputstream and dataoutputstream are decorative classes for input and output streams in Java, which are easy to use. Today we will discuss the encoding problems encountered when using this class. Zookeeper
Package COM. vincent. example; import Java. io. datainputstream; import Java. io. dataoutputstream; import Java. io. fileinputstream; import Java. io. fileoutputstream; import Java. io. ioexcept
Usage and precautions of datainputstream and dataoutputstream
Import Java. io. *;
If you directly use datainputstream to read the file content, an exception is thrown:
At this time, even the manual income data cannot be read, and there is no content in the file.
Solution: you must first use dataoutputstream to write data, and then use datainputstream to re
// Remember the data type that is used for output,
// For example, DOS. writeint (100); write, read: DIS. readutf () sometimes has unexpected errors, so you must always remember what data type is used for data type output reading.
// Datainputstream (binary input stream)
Public class datainputstreamdemo {
// Binary stream (read operation)
Public static void main (string [] ARGs ){
Fileinputstream FCM = NULL;
Data
http://www.verejava.com/?id=16994690613914Package Com.io2;import java.io.*;p ublic class testdatainputstream{public static void Main (string[] args) {O Utputstream OS; try {//to the file in int, Double,boolean, String to Data OS = new FileOutputStream ("Res/data . Dat ")); DataOutputStream dos=new dataoutputstream (OS); Dos.writeutf ("Zhang San"); Dos.writeint (20); Dos.writeboolean (TRUE); Dos.writedouble (10.2);
Example program: Packageio;ImportJava.io.ByteArrayInputStream;ImportJava.io.ByteArrayOutputStream;ImportJava.io.DataInputStream;ImportJava.io.DataOutputStream;Importjava.io.IOException; Public classTestdatastream { Public Static voidMain (string[] args) {/*** Create a byte array in memory, Bytearrayoutputstream this pipe is godless to the memory*/Bytearrayoutputstream BAOs=NewBytearrayoutputstream (); //writes the basic Java data type to the output streamDataOutputStream dos =NewDataOutputStream
Java io is really confusing, since there are FileWriter can write the character stream, why create DataOutputStream can also input character flow to the file. The following demo shows that files created by DataOutputStream can be read by FileReader.
DataInputStream (data input stream), source and example
DataInputStream Introduction
DataInputStream is the data input stream. It inherits from FilterInputStream.
DataInputStream is used to decorate other input streams, which "allows applications to read basic Java data types from the underlying input stream in a ma
;Private int _ length;Private int _ id;Private datainputstream _ din;
Public Record (recordstore RS ){-This (RS, 100 );}
Public Record (Recordstore RS, int initialrecordsize ){_ Rs = RS;_ DATA = new byte [initialrecordsize];_ Din = new datainputstream (New bytearrayinputstream (_ DATA ));_ Length =-1;}
Public byte [] getbytearray () {return _ data ;}
Public int getlength () {return _ length ;}
Public byte [
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.