• 高效 告别996,开启java高效编程之门 4-5TWR进阶与特殊情况


    1    重点:

    1.1  TWR简介

    1.2  class反编译查看TWR方式关闭物理流资源

    2    TWR简介

    ◆Java7引入新特性
    ◆优雅关闭资源
    ◆一种Java语法糖

    3    class反编译查看TWR方式关闭物理流资源idea内置工具class反编译
    //
    // Source code recreated from a .class file by IntelliJ IDEA
    // (powered by Fernflower decompiler)
    //
    
    package com.imooc.zhangxiaoxi.resource;
    
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import org.junit.Test;
    
    public class FileCopyTestNew {
        public FileCopyTestNew() {
        }
    
        @Test
        public void fileCopyTestNew() {
            String fileInputStreamUrl = "lib2/FileCopyTest.java";
            String fileOutputStreamUrl = "targetTest/target2.txt";
    
            try {
                FileInputStream fileInputStream = new FileInputStream(fileInputStreamUrl);
                Throwable var4 = null;
    
                try {
                    FileOutputStream fileOutputStream = new FileOutputStream(fileOutputStreamUrl);
                    Throwable var6 = null;
    
                    try {
                        int conent;
                        try {
                            while((conent = fileInputStream.read()) != -1) {
                                fileOutputStream.write(conent);
                            }
                        } catch (Throwable var22) {
                            var6 = var22;
                            throw var22;
                        }
                    } finally {
                        $closeResource(var6, fileOutputStream);
                    }
                } catch (Throwable var24) {
                    var4 = var24;
                    throw var24;
                } finally {
                    $closeResource(var4, fileInputStream);
                }
            } catch (FileNotFoundException var26) {
                var26.printStackTrace();
            } catch (IOException var27) {
                var27.printStackTrace();
            }
    
        }
    }
    4    课程缺失
    5    资源关闭特殊情况

    ◆资源对象被return的情况下,由调用方关闭
    ◆ByteArraylnputStream等不需要检查关闭的资源对象,
    ◆使用Socket获取的InputStream和OutputStream对象不需要关闭

  • 相关阅读:
    手机文件夹的emulated什么意思
    数据结构
    Django简介
    forms组件
    前端css
    mysql进阶知识
    mysql入门知识
    html文档知识补充
    前端基础
    python 面试题
  • 原文地址:https://www.cnblogs.com/1446358788-qq/p/12967384.html
Copyright © 2020-2023  润新知