Concepts and recursive algorithms in Java streaming

Source: Internet
Author: User

File class:

Java.io.File

   Basic methods;

Gename: Get file name

GetPath: Get File path

Length: Get File size

Isdirectory: Judging If this thing is not a directory

Isfile: Judging this thing is not a file

Listfiles: Gets all the files and folders under the current path

IO stream

  What is a stream

Stream, which can be seen as a conduit for reading the data of a file

Raw data is used in the form of binary data transmission,

File---10111010--> program

File <--10111010---Program

  Classification of streams

Follow the direction of the data flow

Input stream, output stream

Input stream: Move data from file to program

Output stream: From the program to the file to go data

The data is processed in different units:

The eight data types Occupy bytes:

BYTE (1), short (2), int (4), Long (8)

Float (4), double (8)

Boolean (1)

CHAR (2)

Byte stream (ends with stream), character stream (ends with reader, writer)

BYTE stream: 8 bits of bytes, read data in one byte

Character stream: Two bytes, one character per unit

According to the function of

node flow, processing flow

Node stream: Only one root pipe sleeve is transferred on the file

Process flow: Process the node flow, enhance the function of the pipeline, equivalent to a layer on the pipe

  The stream provided by the JDK

Provides four basic abstract classes: InputStream, OutputStream, Reader, Writer

Basic methods of InputStream:
int read (): Each time this method is called, a byte is read and returned as an integer

int read (byte[] buffer---buffer): Let the stream read one buffer at a time, and then unified processing, first exists in the buffer, the return value of int is to return the actual number of bytes read (the principle of damage to the hard disk)

int read (byte[] buffer, int offset, int length): is also a buffer that reads the number of bytes of length in buffer, and starts at the offset position of buffer,

The return value is the actual number of bytes read

Close (): Close Resource

  Basic methods of OutputStream:

void write (int b)

void Write (byte[] b)

int read (byte[] buffer, int offset, int length)

Close ()

Flush (): Writes out all the files in the buffer

In a good habit of using the flow, first flush, then close

 Basic methods of Reader:

int read ()

int read (char[] c)

int read (char[] c, int offset, int length)

Close ()

  The basic method of writer

void Write ()

void Write (char[] c)

void Write (char[] c, int offset, int length)

Write a string directly out, inside the string there is a method S.tochararray (), check API

void Write (String s)

void Write (String s, int offset, int length)

Close ()

Flush ()

File stream (byte stream, character stream)

Buffered streams

Convert Stream---> byte-character

Data Flow---> Eight data types

Print Stream--->system.out.println ();

Object Flow--->

  Recursive instances:

 PackageCom.hanqi;ImportJava.io.File; Public classTestfiledigui { Public Static voidMain (string[] args) {intA = 4; * 8*7*6....*1intj =fact (a);                System.out.println (j); File File=NewFile ("E:\\java\\folder"); //System.out.println (File.exists ());file[] Files =File.listfiles ();  for(inti = 0; i < files.length; i++) {System.out.println (Files[i].getname ()); } factfile (File,0); }         Public Static voidConsoleintk) { for(inta=0;a<k;a++) {System.out.print ("   "); }    }         Public Static voidFactfile (File file,intlength) {        if(File.exists () &&file.isdirectory ()) {file[] fs=File.listfiles ();  for(inti = 0;i<fs.length;i++) {Console (length);                System.out.println (Fs[i].getname ()); Factfile (fs[i], length+ 1); }        }    }     Public Static intFactinti) {intresult = 0; if(i==1) {            returni; } Else{result= i * fact (i-1); }        returnresult; }    }

Concepts and recursive algorithms in Java streaming

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.