JDK7新特性
2016-03-16 12:26
471 查看
package cn.itcast_03; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; public class Demo { public static void main(String[] args) { // 二进制字面量 int x = 0b100101; System.out.println(x); // 数字字面量可以出现下划线 int y = 1_1123_1000; // 不能出现在进制标识和数值之间 int z = 0x111_222; // 不能出现在数值开头和结尾 int a = 0x11_22; // 不能出现在小数点旁边 double d = 12.3_4; // switch 语句可以用字符串?自己回顾 // 泛型简化 ArrayList<String> array = new ArrayList<>(); // 异常的多个catch合并 method(); } private static void method() { // try-with-resources 语句 // try(必须是java.lang.AutoCloseable的子类对象){…} try { FileReader fr = new FileReader("a.txt"); FileWriter fw = new FileWriter("b.txt"); int ch = 0; while ((ch = fr.read()) != -1) { fw.write(ch); } fw.close(); fr.close(); } catch (IOException e) { e.printStackTrace(); } // 改进版的代码 try (FileReader fr = new FileReader("a.txt"); FileWriter fw = new FileWriter("b.txt");) { int ch = 0; while ((ch = fr.read()) != -1) { fw.write(ch); } } catch (IOException e) { e.printStackTrace(); } } }
相关文章推荐
- java线程池---编写自己的线程池
- 有关Java集合类温习
- Java多核cpu多线程运行效率分析
- JDK5新特性之枚举
- 0000eclipse关键快捷键
- Spring加载XML配置文件
- Eclipse中svn设置提交时忽略某些文件夹和文件
- RxJava学习笔记4
- java中的类的初始化顺序详解
- 【转】java中的集合和数组
- 关于java.net.UnknownHostException: Unable to resolve host "xx": No address associated with hostname
- 如何修改struts上传文件大小
- Java中synchronized与java.util.concurrent.locks.Lock区别
- SessionFactory中getCurrentSession地址的对比
- Java并发编程:线程池的使用
- Java NIO系列教程(八) SocketChannel
- 使用RxJava实现EventBus
- java 比较两个二叉树是否相等
- 使用spring mvc返回JSON,chrome可以,firefox不行的问题定位
- Struts2 Convention Plugin ( struts2 零配置 )