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
of Trend Micro China Software Development Center, has more than more than 10 years of practice and research experience in the field of information science and engineering, and has a number of Chinese and American patents. Focus on JVM performance tuning and big data and its practices, like digging into the inside of technology and being bored.LaoMaster's degree from Shanghai Jiaotong University and now an advanced software support consultant at SAP USA. Hobby language, mathematics, design, in r
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
First, the purpose and requirements of the experimentExperimental purposes and requirements: Students are required to learn and understand the Java Stream programming theory on the basis of learning and understanding of the classroom learning content, learning and gradually master the programming and debugging of the stream program, to learn the correct choice of
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 Stream principle Requirements从"Apple" "Bug" "ABC" "Dog"中选出以A开头的名字,然后从中选出最长的一个,并输出其长度1. The most straightforward implementationDisadvantages
Too many iterations
Frequently produces intermediate results, performance unacceptable
2. Common wordingint0;for(String str : strings){ if(str.startsWith("A")){// 1. filter(), 保留以张开头的字符串 int l
: File F = new file ("D:\\code\\java_blog_code"); 7: //filenamefilter to set filter 8: string[] s = f.list (new FilenameFilter () 9: { Ten: Public Boolean Accept (File dir,string name) One: { : if (Name.endswith (". Java")) : return true; : El
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
JAVA 52nd-IO stream (6) File object
File class
Used to encapsulate files or folders as objects.
Convenient operations on file and folder attributes
The File object can be passed to the stream constructor as a parameter.
1. constructor and Separator
Public static void FileDemo () {// constructor demo // You can encapsulate an existing or nonexistent File or direc
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
functions by nesting filters. For example, the stream is not cached by the buffer by default, that is, each call to read requests the operating system to redistribute one byte. In contrast, it is more efficient to request a block of data and place it in a buffer. If we want to use the buffering mechanism and the data entry method for the file, then we need to use this rather scary constructor sequence:new DataInputStream( new BufferedInputStream(
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 (
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
usually iterate over all the elements and process each element, using flow operations to improve efficiency in parallel processing, to follow "what to do" without limiting what to do, providing the opportunity for integrity optimization to improve efficiencyThe flow surface looks similar to the set, however:1. Streams do not store elements, they are stored in the underlying collection or generated on demand2. Stream operations do not change their sou
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
Flow :Concept: The operation of a file in Java is done in a streaming fashion. A stream is an ordered set of data sequences in Java memory. Java reads the data from the source (file, memory, keyboard, network) into memory, forms a stream, and then writes those streams to ano
): Writes out one byte array at a time* Available () Gets the number of bytes read from the file* Disadvantages: There may be memory overflowFileInputStream fis = new FileInputStream ("to Youth. mp3");FileOutputStream fos = new FileOutputStream ("Copy.mp3");byte[] arr = new byte[fis.available ()];//make a byte array based on file sizeFis.read (arr);//Read all the bytes on the file into the arrayFos.write (arr);//Writes all the bytes in the array once to the fileFis.close ();Fos.close ();# # #IO流
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.