Flow knowledge points

1. Singleton mode code

 Class HuangryInstance{
    
    
//1,私有化构造方法
private HuangryInstance(){
    
    
          }
//2. 创建一个HuangryInstance对象
private static final HuangryInstance  intstance = new HuangryInstance  ();
public static  HuangryInstance getInstance(){
    
    
       return  instance;
    }
}
Class LazyInstance
{
    
    
  private  LazyInstance(){
    
    }
private static LazyInstance instance=null;
public static LazyInstance  getInstatnce(){
    
    
if(instance==null){
    
    
     instance = new LazyInstance ();
}
     return instance  ;
    }
}

2. Stream classification
Direction: Input stream (read) Output stream (write)
unit: byte stream (wide range of application) character stream (high efficiency)
function: node stream (direct contact with data source) processing stream (contact is other flow)

3. The abstract parent class of stream
InputStream
OutputStream
Reader
Writer

4. Four file streams
FileInputStream
FileOutputStream
FileReader
FileWriter

5. Copy file code
1> source file
2> target file
3> input and output stream object
4> read
5> write
6> close stream

//字符流的使用
File src = new File(“a.txt”);
File dest = new File(“b.txt”);
FileReader reader = new FileReader(src);
FileWriter writer = new FileWriter(dest);
char[] cs = new char[10];
int len = 0;
While((len = reader.read(cs))!=-1){
    
    
    wirter.write(cs,0,len);
    System.out.println("复制完成");
    writer.flush();
}
if(reader!=null){
    
    
       reader.close()}
if(writer!=null){
    
    
       writer.close();
}
//字节流的使用
//1.源文件
				File src=new File("a.txt");
				//2.目标文件
				File dest= new File("c.txt");
				//3.创建输入输出流对象
				FileInputStream fis =null;
				FileOutputStream fos =null;
				try {
    
    
					 fis = new FileInputStream(src);
					 fos = new FileOutputStream(dest);
					//4.读		
						byte[] bs = new byte[10];
						int len = 0;
						while((len = fis.read(bs))!=-1){
    
    
							// 5.写到c.txt
							fos.write(bs, 0, len);
						}
						System.out.println("复制完成");
                    if(fis!=null){
    
    
                            fis.close()}
                 if(fos!=null){
    
    
                       fos.close();
          }

6. Features of static keyword
1> Can modify
attributes, methods, code blocks, internal classes
2> What are the characteristics of the
call?
It can be called by object or by class name (recommended)
3> What are the characteristics of
attributes ? Static properties will be static Only one copy is stored in the domain, and multiple objects share this space.
The attribute values ​​of all objects will be the same.
Disadvantage: It will cause all attribute values ​​to be the same, but not all attributes are consistent.
Advantages: Save memory
4> What are the characteristics of the method
Allow inheritance, but not allow rewriting, allow overloading

Guess you like

Origin blog.csdn.net/Echoxxxxx/article/details/112647992