) buffer stream (one of the processing flows)InputStream FileInputStream BufferedinputstreamOutputStream FileOutputStream BufferedoutputstreamReader FileReader BufferedReaderWriter FileWriter BufferedWriterFor non-text files (video, picture, audio), you can only use the byte stream to implement the file copy FileInputStream, FileOutputStreamFor text files, you can also use only character streams FileReader,
();
}
2) Read the file data from the resource asset
String fileName = "Test.txt"; File name
String res= "";
try{
//Get the asset data stream in the resource
inputstream in = Getresources (). Getassets (). open (fileName);
int length = in.available ();
byte [] buffer = new Byte[length];
In.read (buffer);
In.close ();
res = encodingutils.getstring (buffer, "UTF-8");
} catch (Exception e) {
e.printstacktrace ();
}
Second, read and write/data/data/
Writ
input streams and can read byte information into memory. Defines the basic commonality function method of byte input streamFor example:public void Close (): closes this input stream and frees any system resources associated with this flowpublic abstract int Read (): reads the next byte of data from the input streampublic int read (byte[] b): Reads some number of bytes from the input stream and stores them in byte array bNote: You must call the Close method to free system resources when you have
Java.util.Properties description.
This class is mainly read property configuration file, two file types: Normal file format is key = Value;xml file.1) Key = Value example is as follows:public class Testproperties {public static void main (string[] args) {Properties Properties = new Properties (); FileInputStream fileinputstream;try {fileinputstream = new
{FileInputStream fiis = new FileInputStream ("fos.txt"); // int num = fiis. available (); byte [] buf = new byte [FCM. available ()]; // defines a buffer that is just right. You don't have to loop. Fiis. read (buf); System. out. println (new String (buf); Sox. close ();} public static void readFile_2 () throws IOException {FileInputStream FD = new
will be more troublesome, so it is generally like the next rule: if the input/output content is a text file, you should consider using the ghost stream; if the input/output content is binary (slice or audio file), byte streams should be considered.
The following describes four base classes, InputStream, Reader, OutputStream, and Writer, and lists common subclasses:
The following describes the features and application scenarios of each category:
1. InputStreamReader and OutputStreamWriter a
, you can set another pipe outside this pipe, and the flow over the other pipe is called the flow of processing. Why do we need to process the flow? This is with the flow of impurities, you have to filter it, you can set a layer of pipe to filter these impurities.3.1. Node stream type A node stream is a pipe that plugs directly into the data source, reads data directly from the data source, or writes data directly to the data source. A typical node stream is a file stream: A file's byte input s
com.easyReport.read.temp.ReadTemp;Import com.easyReport.read.temp.TxtBytePropertyTemp;Import com.easyReport.read.temp.TxtReadTemp;public class Testtxtbyte extends Abstracttxttest@Overridepublic void Test () {FileInputStream FileInputStream;try {FileInputStream = new FileInputStream (New File ("Testfile/test7.txt"));Te
can only be read operation, the output stream can only write operations, the program needs to be transmitted according to the different characteristics of the data to use a different flow. a class or interface that is related to a Java stream operation:
Java Streaming class diagram structure:
Java io Stream object 1. Input byte stream inputstream definition and structure description:
You can see from the inheritance graph of the input byte stream:
InputStream is the parent class of all input by
Link Address: http://blog.sina.com.cn/s/blog_407a68fc0100f628.htmlOriginally Java was not supporting the processing of text files, in order to compensate for this shortcoming introduced the reader and writer two classes.java.io There are two abstract classes: InputStream and ReaderInputStream is a superclass of all classes that represent byte input streamsReader is an abstract class for reading stream of charactersThe InputStream provides a byte stream reading, not a text read, which is fundamen
, usingFileInputStream Getting filesIn 1 we talked about using Openfileoutput (name, mode) and Openfileinput (name) to get the output stream and the data input stream separately, which is provided in the original Java FileInputStream and FileOutputStream classes, respectively, inherit from InputStream and OutputStream, and in Android through this two class can also get input stream and output stream.1. How to use FileInputStreamHere's how the
("/app/servlet2");B, Response.sendredirect ("Servlet2");C, Response.setstatues (302);Response.setheader ("Location", "/app/servlet2");D, Response.setheader ("Refresh", "0;url=/app/servlet2");Answer: ABCDTest Centers: servlet resource files in16. There is a 1.jpg file under the directory in the app's web app named app, now you need to get the byte input stream in the servlet that points to the file. Which of the following options can be implemented (C)(difficulty B)A,
use of three-byte throttling 6) FileOutputStream---> Implements a method for writing byte data to a file FileOutputStream inherits the OutputStream abstract class.Methods in the FileOutputStream class:Example code 1:Operation Result: file copy Example code 2:Operation Result: 7) DataOutputStream class/datainputstream class For the extension of the "stream" function, you can read int, long, character and other types of data more. This class embodies the decorative patterns in the design pattern.
size) reads the data into a byte array buf, starting from the start position and placing up to how many(4) Output streamOut.write (int b) writes out a byte-to-stream and writes the lower 8 bits of BOut.write (byte[] buf) writes the byte array buf to the streamOut.write (byte[], int start, int size)(5) Subclass FileInputStream ---specifically implements reading data on a file/read file contents, output to console according to 16, and 10 byte newline p
byte unsigned to fill in the lower eight bits of the int. -1 is EOFIn. read (byte [] buf) read data to fill in the byte array bufIn. read (byte [] buf, int start, int size) read data is filled into the byte array buf, starting from the start position of the buf, storing the size data4) basic method of output streamOut. write (int B) writes a byte to the stream, and B's low 8 bitsOut. write (byte [] buf) writes the buf byte array to the streamOut. write (byte [] buf, int start, int size)5)
) {E.printstacktrace (); } } } } }We first empty the contents of the ReaderTest.txt file, the result of the operation is as follows (do not empty the line, just run the results of the blogger's different):Three, the word stream instance3.1. Before instanceAgain, as mentioned earlier, "As long as you are dealing with plain text data, you should prioritize the use of character streams, in addition to the byte stream."Here bloggers posted a character stre
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.