FileInputStream, each time it reads 512 bytes from the source program file Openfile.java, stores it in buffer buffers, and then constructs the string new string with the value in buffer ( Buffer) is displayed on the screen. The program is as follows (this example is placed in the package Biz.1cn.stream, in addition, please create a TestFile.txt file in the root directory for normal operation):1 PackageBiz.1cn.stream; 2 ImportJava.io.FileInputStream; 3 Importjava.io.IOException; 4
outputstream to writer Transformation Bridge, its subclass filewriter is actually a concrete class to implement this function; * */public class IO {public static void Main (string[] args) throws IOException {//character stream string path = "Data/data"; BufferedReader br = new BufferedReader (new InputStreamReader (New FileInputStream (path), "Utf-8")); String line = "", while (line = Br.readline ())! = nu
frees all system resources associated with the stream. Therefore, you can only call the Close method of the outer flow to close the inner laminar flow of its adornment, to verify the example:Throws Exception { new FileOutputStream ("D:\\a.txt"new OutputStreamWriter (FOS, "UTF-8" New BufferedWriter (OSW); Bw.write ("Java IO close Test"); Bw.close ();}Ver
The Java.io.File class is used to represent files (directories)The file class is used only for information (name, size, etc.) that represent files (directories) and cannot be used for access to file contentRandomaccessfile Java provides access to the contents of a file that can be read or written.Randomaccessfile supports random access to files and can access any location in the file(1) Java file modelThe f
whose data is written to a file. ObjectOutputStream This class will implement serialization of the serialized object after it is written to the specified place. the output stream of the PipedOutputStream pipeline is the sending end of the pipeline.3.objectstream,inputstream are often used with FileInputStream and FileOutputStream. (used when initializing)New ObjectOutputStream (new FileOutputStream ("logon.out"));The 4.File class does
the reason and thought of character stream appearing ? Because the byte stream operation Chinese is not particularly convenient, so Java provides a character stream. Character stream = byte stream + encoding table.
Coding
too many forced type conversions.
Compiler Optimization: Java 8 adds the parameter name of the method to the bytecode so that the parameter name can be obtained through reflection at runtime. You only need to use the-parameters parameter during compilation.
Parallel Array: Supports parallel processing of arrays, mainly the parallelSort () method, which can greatly improve the speed of array sorting on mu
stream.Conversion flow: Inputstreamreader/outputstreamwriter, converting bytes into charactersBuffered buffer stream:: Bufferedinputstream,bufferedoutputstream,bufferedreader,bufferedwriter, is a processing stream with buffers, bufferingThe main purpose of the district is to avoid dealing with the hard disk every time and improve the efficiency of data access.Object flow: Objectinputstream,objectoutputstre
input and output. They convert byte streams into the bridge converter of the dense stream and can specify the encoding/decoding method.Reader and writer (parent stream class, all parent stream types)1) Use of Java TechnologyUnicodeAnd provides a 16-bit stream to process cha
): Pipedreader, PipedWriter, PipedInputStream, PipedOutputStream
3.File file Stream
Read and write to files: FileReader, FileWriter, FileInputStream, FileOutputStream
4. Objectserialization
Object input, Output: ObjectInputStream, ObjectOutputStream
5.DataConversion Data Flow
Read and write by basic data type (processed data is the basic type of Java (such as Boolean, Byte, Integer, and floating-point numbe
I. Input and Output1. Stream represents any data source capable of producing data or any receiving source capable of receiving data. In Java I/O, all streams (including input and out stream) have two types:1.1 byte-oriented streamA byte-oriented stream that reads or writes information to a
JAVA 56th-IO stream (10) Object serialization and deserialization RandomAccessFile, io serialization
Operation object
ObjectInputStream and ObjectOutputStream
The operated object must implement Serializable (Mark Interface)
ObjectOutputStream writes the basic data types and graphics of Java objects to OutputStream. You can use ObjectInputStream to read (refactor
The difference between a character stream and a byte streamTake a look at an example of the previous article:1 Public Static voidMain (string[] args)throwsException2 {3File File =NewFile ("D:/writer.txt");4Writer out =NewFileWriter (file);5 //declares a String type object6String str = "Hello World!!!";7 out.write (str);8 out.close ();9 Ten //Read File Operation OneReader in =Newfilereader (
The difference between a character stream and a byte streamTake a look at an example of the previous article:1 public static void main (string[] args) throws Exception 2 {3 file File = new file ("D:/writer.txt"); 4 writer ou t = new FileWriter (file); 5 //declares a String type Object 6 string str = "Hello world!!!"; 7 out.write (str); 8 out.close (); 9 // Read file operation
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 input and output can be divided into two categories, streaming and non-streaming operations, streaming operations mainly concerned with the reading and writing of the contents of the file, non-streaming operations are mainly used for file management on disk. The following first learns streaming data operations.FlowSimilar to C + +, the concept of flow is also provided in Java to handle input and output
Java Base IO Stream (i) byte stream IO flow system is too large, involving a variety of flow objects, I think it is necessary to summarize.What is an IO stream, IO represents input, Output, and the flow is an abstraction of the data transfer from the original source to the target medium. Typical data sources and targe
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.