zoukankan      html  css  js  c++  java
  • JDK7新特性

    二进制字面量

    数字字面量可以出现下划线

    switch语句可以用字符串

    泛型简化

    异常的多个catch合并

    try..with...resource语句

    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.ArrayList;
    
    public class Test {
    	public static void main(String[] args) throws Exception {
    		// 二进制字面量
    		int x = 0b100101;
    		System.out.println(x);
    
    		// 数字字面量可以出现下划线
    		int y = 100_1000;
    		System.out.println(y);
    
    		// switch语句可以用字符串
    
    		// 泛型简化
    		ArrayList<String> array = new ArrayList<>();
    
    		// 异常的多个catch合并
    
    		// try..with...resource语句
    		method1();// 旧版
    		method2();// 改进版
    	}
    
    	private static void method1() {// 旧版
    		try {
    			FileReader fr = new FileReader("E:\zikao\file\cs.txt");
    			FileWriter fw = new FileWriter("E:\zikao\file\cs1.txt");
    			int ch = 0;
    			while ((fr.read()) != -1) {
    				fw.write(ch);
    			}
    			fw.close();
    			fr.close();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}
    
    	private static void method2() {// 改进版
    		try (FileReader fr = new FileReader("E:\zikao\file\cs.txt");
    				FileWriter fw = new FileWriter("E:\zikao\file\cs1.txt");) {
    			int ch = 0;
    			while ((fr.read()) != -1) {
    				fw.write(ch);
    			}
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}
    }
    
  • 相关阅读:
    SVN 常用keywords 记录
    HTML5新特性介绍
    php文件上传错误代码
    MySQL的 Grant命令权限分配
    前端开发工具整理
    Java多线程编程经验谈
    一套密码强度判断方案
    傲游浏览器下Flash和Js交互问题
    在xml中使用&和字符
    ibatis和myibatis
  • 原文地址:https://www.cnblogs.com/denggelin/p/6358566.html
Copyright © 2011-2022 走看看