20145122 《Java程序设计》第8周学习总结

教材学习内容总结

1.NIO使用频道(channel)来衔接数据节点,对数据区的标记提供了clear(),rewind(),flip(),compact()等高级操作。
2.想要取得channel的操作对象,可以使用channels类。
3.Buffer的直接子类们都有一个allocate()静态方法,可以让你指定Buffer容量。
4.Buffer的容量大小可以使用capacity()方法取得。
5.NIO2文件系统API提供一组标准接口与类
6.应用程序开发者可以通过java.nio.file包中FileSystem,Paths,Files等提供的静态方法,取得相关操作对象或进行各种文件系统操作。
7.java.util.logging包提供了日志功能相关类与接口。
8.使用日志的起点是Logger类,要取得Logeer实例,必须使用Logger的静态方法getLogger()。
9.可以通过logging.properties来设定Logger组态,启动JVM时,指定java.util.logging.
10.config.file系统属性为.properties名称。
11.可以使用date来取得完整日期时间,可单纯使用tostring()取得日期文字描述,或使用dateformat格式化日期。
12.规则表示式主要用于字符,字符串格式比较。

教材学习中的问题和解决过程

这章的内容对我们很有实际作用,NIO2能让我们了解系统属性和容量。


package disk;

import java.io.IOException;
import static java.lang.System.out;
import java.nio.file.*;
import java.text.DecimalFormat;

public class Disk {
    public static void main(String[] args) throws IOException {
        if (args.length == 0) {
            FileSystem fs = FileSystems.getDefault();
            for (FileStore store: fs.getFileStores()) {
                print(store);
            }
        } 
        else {
            for (String file: args) {
                FileStore store = Files.getFileStore(Paths.get(file));
                print(store);
            }
        }
    }
    
    public static void print(FileStore store) throws IOException {
        long total = store.getTotalSpace();
        long used = store.getTotalSpace() - store.getUnallocatedSpace();
        long usable = store.getUsableSpace();
        DecimalFormat formatter = new DecimalFormat("#,###,###");
        out.println(store.toString());
        out.printf("	- 總容量	%s	位元組%n", formatter.format(total));
        out.printf("	- 可用空間	%s	位元組%n", formatter.format(used));
        out.printf("	- 已用空間	%s	位元組%n", formatter.format(usable));
    }
}

本周代码托管截图

其他(感悟、思考等,可选)

本周的学习内容让我们可以进行各种文件系统操作也了解了一些新的API功能特性,比较实用。

学习进度条

代码行数(新增/累积) 博客量(新增/累积) 学习时间(新增/累积) 重要成长
第一周 100/100 2/2 10/10
第二周 150/250 1/3 10/20
第三周 100/350 1/4 10/30
第四周 320/670 1/5 30/60
第五周 700/1370 1/6 30/90
第六周 700/2070 2/8 30/120
第七周 700/2770 2/10 30/150
第八周 500/3270 2/12 30/150
原文地址:https://www.cnblogs.com/20145122chengzhiyin/p/5424501.html