import java.io.File
import java.nio.file._ import scala.collection.mutable.ArrayBuffer
/**
* Created by EX-CHENZECHAO001 on 2018-04-02.
*/
class Chapter09 {
// 9.7 访问目录
def subdirs(dir: File): Iterator[File] = {
val children = dir.listFiles().filter(_.isDirectory)
children.toIterator ++ children.toIterator.flatMap(subdirs(_))
}
implicit def makeFileVisitor(f: (Path) => Unit) = new SimpleFileVisitor[Path] { }
} object Chapter09 extends App{
val files = new Chapter09().subdirs(new File("D:\\chenzechao\\_learn"))
for(file <- files){
println(file.getName)
}
} // 9.8 序列化
class Person98 extends Serializable { }
// 如果接受缺省ID,可略去@SerialVersionUID
// 按常规方式对对象进行序列化和反序列化
object Person98 {
val fred = new Person98()
import java.io._
val out = new ObjectOutputStream(new FileOutputStream("/tmp/abc.obj"))
out.writeObject(fred)
out.close()
val in = new ObjectInputStream(new FileInputStream("/tmp/abc.obj"))
val saveFred = in.readObject().asInstanceOf[Person98] // Scala集合类都是可序列化的
class Person98_01 extends Serializable{
private val friends = new ArrayBuffer[Person98]
}
} // 9.8 进程控制
import sys.process._
// "ls -al .."
// sys.process包包含一个从字符器到ProcessBuilder对象的隐式转换。!操作符执行的就是这个ProcessBuilder对象
// !操作符返回的被执行程序的返回值:程序成功执行的话就是0,否则就是显示错误的非0值
// 如果使用!!则返回命令执行结果
val result = "ls -al .." !!

chapter09的更多相关文章

  1. Chapter09 项目

    Chapter09 项目 房屋出租系统(面向对象中级) 9.1 房屋出租系统-需求 9.1.1项目需求说明 实现基于文本界面的<房屋出租软件>. 能够实现对房屋信息的添加.修改和删除(用数 ...

  2. Redux你的Angular 2应用--ngRx使用体验

    Angular2和Rx的相关知识可以看我的Angular 2.0 从0到1系列第一节:Angular 2.0 从0到1 (一)第二节:Angular 2.0 从0到1 (二)第三节:Angular 2 ...

  3. Hibernate Validator 6.0.9.Final - JSR 380 Reference Implementation: Reference Guide

    Preface Validating data is a common task that occurs throughout all application layers, from the pre ...

  4. ASP.NET Core 入门教程 9、ASP.NET Core 中间件(Middleware)入门

    一.前言 1.本教程主要内容 ASP.NET Core 中间件介绍 通过自定义 ASP.NET Core 中间件实现请求验签 2.本教程环境信息 软件/环境 说明 操作系统 Windows 10 SD ...

  5. 《Linux就该这么学》第十二天课程

    使用ssh服务管理远程主机 绑定两块网卡 原创地址:https://www.linuxprobe.com/chapter-09.html 第1步:在虚拟机系统中再添加一块网卡设备,请确保两块网卡都处在 ...

  6. List遍历三种方法:1.for 2.增强性for 3.迭代器

    package chapter09; import java.util.ArrayList;import java.util.Iterator;import java.util.List; /* * ...

  7. 集合List和ArrayList的示例

    package chapter09; import java.util.ArrayList;import java.util.List; /* * List * ArrayList底层是数组 * 特点 ...

  8. 《Gradle权威指南》--Android Gradle多项目构建

    No1: Android多项目设置 目录结构: MyProject/ setting.gradle app/ build.gradle libraries/ lib1/ build.gradle li ...

  9. Entity Framework 6 Recipes 2nd Edition(目录索引)

    Chapter01. Getting Started with Entity Framework / 实体框架入门 1-1. A Brief Tour of the Entity Framework ...

随机推荐

  1. 【LeetCode】001. Two Sum

    题目: Given an array of integers, return indices of the two numbers such that they add up to a specifi ...

  2. GCC生成动态库

    main.c #include <stdio.h> void hello(void); int main(int argc, char ** argv) { printf("Th ...

  3. Python:删除字符串中的字符

    一.删除字符串两端的一种或多种字符 #strip().lstrip().rstrip()方法:(默认删除空格符) A.list.strip(字符):删除字符串两端的一种或多种字符: #例:删除字符串s ...

  4. java流类

    总结:new FileInputStream package com.ds; import java.io.*; import com.da.fgbv; public class rter { pub ...

  5. Spring Boot中使用RabbitMQ

    很久没有写Spring Boot的内容了,正好最近在写Spring Cloud Bus的内容,因为内容会有一些相关性,所以先补一篇关于AMQP的整合. Message Broker与AMQP简介 Me ...

  6. js产生不同的随机数

    前言:前几天写到一个程序,用到要使用不同随机数的方法,结果愣是整了半天没整出来,说来也是惭愧啊(亏我还是软件工程的学生,其实这个问题以前遇到过,只是我逃避了,哎,自己刨的坑终究会把自己陷进去,╮(╯▽ ...

  7. selenium如何获取已定位元素的属性值?

    HTML源代码: <div class="res-status" data-fortune="5" data-selfsos="" d ...

  8. leetcode笔记-1 twosum

    # -*- coding: utf-8 -*- #!/bin/env python # Python2.7 nums = [2, 4, 7, 0, 12, 6] print sorted(range( ...

  9. BLUETOOTH_DEVICE_INFO 函数

    typedef struct _BLUETOOTH_DEVICE_INFO { DWORD dwSize; BLUETOOTH_ADDRESS Address; ULONG ulClassofDevi ...

  10. HBase 二级索引与Coprocessor协处理器

    Coprocessor简介 (1)实现目的 HBase无法轻易建立“二级索引”: 执行求和.计数.排序等操作比较困难,必须通过MapReduce/Spark实现,对于简单的统计或聚合计算时,可能会因为 ...