fanjialong преди 9 месеца
родител
ревизия
d5eb67e758
променени са 25 файла, в които са добавени 1063 реда и са изтрити 2 реда
  1. 0 1
      src/main/java/com/sf/day14/_03_string/test/TestStringContact.java
  2. 0 1
      src/main/java/com/sf/day17/_02_map/TestHashMap.java
  3. 82 0
      src/main/java/com/sf/day18/_01_treeset/TestTreeSet.java
  4. 60 0
      src/main/java/com/sf/day18/_01_treeset/dt/Student.java
  5. 209 0
      src/main/java/com/sf/day18/_02_util/Test.java
  6. 29 0
      src/main/java/com/sf/day18/_02_util/dt/A.java
  7. 29 0
      src/main/java/com/sf/day18/_02_util/dt/B.java
  8. 54 0
      src/main/java/com/sf/day18/_02_util/dt/Fruit.java
  9. 9 0
      src/main/java/com/sf/day18/_02_util/util/CalcUtil.java
  10. 81 0
      src/main/java/com/sf/day18/_03_exception/Test.java
  11. 5 0
      src/main/java/com/sf/day18/_03_exception/dt/Anmail.java
  12. 4 0
      src/main/java/com/sf/day18/_03_exception/dt/Cat.java
  13. 4 0
      src/main/java/com/sf/day18/_03_exception/dt/Dog.java
  14. 10 0
      src/main/java/com/sf/day18/_03_exception/dt/User.java
  15. 104 0
      src/main/java/com/sf/day19/_01_exception/Test.java
  16. 93 0
      src/main/java/com/sf/day19/_01_exception/Test1.java
  17. 28 0
      src/main/java/com/sf/day19/_01_exception/Test2.java
  18. 7 0
      src/main/java/com/sf/day19/_01_exception/able/ILoginAble.java
  19. 34 0
      src/main/java/com/sf/day19/_01_exception/able/impl/LoginAbleImpl.java
  20. 7 0
      src/main/java/com/sf/day19/_01_exception/dt/User.java
  21. 10 0
      src/main/java/com/sf/day19/_01_exception/ex/AgeException.java
  22. 18 0
      src/main/java/com/sf/day19/_01_exception/ex/LoginException.java
  23. 19 0
      src/main/java/com/sf/day19/_01_exception/util/Result.java
  24. 44 0
      src/main/java/com/sf/day19/_01_exception/vo/LoginVO.java
  25. 123 0
      src/main/java/com/sf/day19/_02_file/_01_file_api/TestFileApi.java

+ 0 - 1
src/main/java/com/sf/day14/_03_string/test/TestStringContact.java

@@ -1,6 +1,5 @@
 package com.sf.day14._03_string.test;
 
-import sun.nio.ch.sctp.SctpNet;
 
 import java.util.Arrays;
 import java.util.Scanner;

+ 0 - 1
src/main/java/com/sf/day17/_02_map/TestHashMap.java

@@ -3,7 +3,6 @@ package com.sf.day17._02_map;
 import com.sf.day17._02_map.able.ILoginAble;
 import com.sf.day17._02_map.able.impl.LoginAbleImpl;
 import com.sf.day17._02_map.dt.Student;
-import sun.nio.ch.sctp.SctpNet;
 
 import java.util.Collection;
 import java.util.HashMap;

+ 82 - 0
src/main/java/com/sf/day18/_01_treeset/TestTreeSet.java

@@ -0,0 +1,82 @@
+package com.sf.day18._01_treeset;
+
+import com.sf.day18._01_treeset.dt.Student;
+
+import java.util.Comparator;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+public class TestTreeSet {
+
+    public static void main(String[] args) {
+
+
+
+        method2();
+
+    }
+
+    private static void method2() {
+        TreeMap<Integer, Student> treeMap = new TreeMap<>(new Comparator<Integer>() {
+            @Override
+            public int compare(Integer o1, Integer o2) {
+                return o2 - o1;
+            }
+        });
+
+        // 1 要求往map当中存数据 key(Integer)-value(Student(id,name,age)) 往里面插入3个key-value
+        treeMap.put(1,new Student(1,"zhangsan",10));
+        treeMap.put(3,new Student(3,"wangwu",30));
+        treeMap.put(2,new Student(2,"lisi",20));
+        // 2 要求要按照id 进行降序
+        // 最终打印出来id 最大的要前面遍历出来每一个key-value 元素
+        for (Map.Entry<Integer, Student> entry : treeMap.entrySet()) {
+            // 3 在遍历的过程中判断如果name名字是张三,那就给他的年龄+10岁
+            Student s = entry.getValue();
+            if("zhangsan".equals(s.getName())){
+                // 就吧年龄加10岁
+                s.setAge(s.getAge() +10);
+                // 吧修改完以后Student 重新放到map当中
+                treeMap.put(entry.getKey(),s);
+            }
+            System.out.println(entry.getKey() +"-"+entry.getValue());
+        }
+
+    }
+
+    public static void method1(){
+        // 测试TreeApi
+        // 1 创建出来一个TreeSet,提供了无参数构造器
+        Map<String,Object> map = new TreeMap<>();
+        map.put("a","123");
+        map.put("c","223");
+        map.put("b","323");
+        map.put("e","44");
+        System.out.println(map);
+        // 如何便利map 拿到map的所有的key -value
+        /**
+         * 遍历map 拿到每一个key 和value
+         *
+         * 方式1: 拿到map当中所有的key ,可以根据key 上map 当中获取他所有的value
+         * 要求在控制台当中  key-value
+         */
+        Set<String> set = map.keySet();
+        for (String key : set) {
+            System.out.println("key:"+ key + " - value:" + map.get(key));
+        }
+
+        /**
+         * 方式2: map.entrySet  获取一个键值对集合
+         * 遍历键值对集合 , 里面元素提供获取key 和获取value 方法
+         * key键- value值  (键值对) 多个这中数据
+         */
+        Set<Map.Entry<String, Object>> set1 = map.entrySet();
+//        Map.Entry<String, Object>  键值对
+        for (Map.Entry<String, Object> entry : set1) {
+            System.out.println(entry);
+            // 获取map 当中key 和map 当中value
+            System.out.println("key: "+ entry.getKey() + "-value:"+ entry.getValue());
+        }
+    }
+}

+ 60 - 0
src/main/java/com/sf/day18/_01_treeset/dt/Student.java

@@ -0,0 +1,60 @@
+package com.sf.day18._01_treeset.dt;
+
+public class Student  {
+    private Integer id;
+    private String name;
+    private Integer age;
+
+    public Student() {
+    }
+
+    @Override
+    public String toString() {
+        return "Student{" +
+                "id=" + id +
+                ", name='" + name + '\'' +
+                ", age=" + age +
+                '}';
+    }
+
+    public Student(Integer id, String name, Integer age) {
+        this.id = id;
+        this.name = name;
+        this.age = age;
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Integer getAge() {
+        return age;
+    }
+
+    public void setAge(Integer age) {
+        this.age = age;
+    }
+
+//    @Override
+//    public int compareTo(Student o) {
+//        if(this.getId() - o.getId()>0){
+//            return 1;
+//        }else if(this.getId() - o.getId()<0){
+//            return -1;
+//        }else{
+//            return 0;
+//        }
+//    }
+}

+ 209 - 0
src/main/java/com/sf/day18/_02_util/Test.java

@@ -0,0 +1,209 @@
+package com.sf.day18._02_util;
+
+import com.sf.day18._02_util.dt.A;
+import com.sf.day18._02_util.dt.B;
+import com.sf.day18._02_util.dt.Fruit;
+import com.sf.day18._02_util.util.CalcUtil;
+
+import java.math.BigDecimal;
+import java.util.*;
+
+
+public class Test {
+    public static void main(String[] args) {
+
+
+//        method3();
+//        method4();
+//        method5();
+//         method6();
+        method7();
+    }
+//    需求3: 有一个水果有(id,name,color)
+//    在静态代码块中初始化5个水果对象存放到集合中,其中2个绿色,1个红色 ,1个蓝色
+//    要求在控制台中输入颜色, 要求返回输入颜色水果, 如果不存在返回空集合
+    private static void method7() {
+        //1 创建出来Scaner 对象
+        Scanner scanner = new Scanner(System.in);
+        //2 拿到我们输入内容
+        System.out.println("请输入颜色:");
+        String color = scanner.next();
+        //3 创建出来一个List 集合
+        List<Fruit> fruits = new ArrayList<>();
+        //4 遍历在静态代码块当中存集合数据
+        List<Fruit> fruits1 = Fruit.fruits;
+        //5 拿到每一个元素
+        for (Fruit fruit : fruits1) {
+            if(color.equals(fruit.getColor())){
+                fruits.add(fruit);
+            }
+        }
+        System.out.println(fruits);
+    }
+
+    //    需求2: 用户输入 10.32 13.00 18.32  8.32 , 要求计算最大值除最小值等于多少要求进行精度计算
+    // Collections.min()  max() BigDecmail
+    private static void method6() {
+        //1 创建出来Scaner对象
+        Scanner scanner = new Scanner(System.in);
+        List<Double> list = new ArrayList<>();
+        //2 循环4此,吧元素添加到集合当中
+        for (int i = 0; i < 4; i++) {
+            System.out.println("请输入内容");
+            list.add(scanner.nextDouble());
+        }
+        //3 找出来最大值和最小值
+        Double max = Collections.max(list);
+        Double min = Collections.min(list);
+        //4 用bigdecmail 把最大值和最小值 包装起来,然后进行计算
+        BigDecimal b1 = new BigDecimal(max);
+        BigDecimal b2 = new BigDecimal(min);
+        System.out.println("最大值除最小值为:" + b1.divide(b2));
+    }
+
+    //    需求1:  用户输入内容 1,5,6,4,3,2  要求 输出[6,5,4,3,2,1]
+    private static void method5() {
+        // 1 创建出来Scaner 对象
+        Scanner scanner = new Scanner(System.in);
+        // 2 循环6次
+        List<Integer> list = new ArrayList<>();
+        for (int i = 0; i < 6; i++) {
+            // 3 把输入元素添加到List 集合当中
+            System.out.println("请输入内容:");
+            int item = scanner.nextInt();
+            list.add(item);
+        }
+
+        // 4 先调用sort 进行排序  , 从小到大
+        Collections.sort(list);
+        // 5 在调用reverse 调过来
+        Collections.reverse(list);
+        System.out.println(list);
+
+
+    }
+
+    /**
+     * Collections 工具类当中常见api
+     */
+    private static void method4() {
+        // Collections 当中是有一些字段
+        // 表示创建一个空list 集合
+        List list = Collections.EMPTY_LIST;
+        Set emptySet = Collections.EMPTY_SET;
+        System.out.println(list);
+        System.out.println(emptySet);
+
+        List<Integer> list1 = Arrays.asList(1, 3, 10, 4, 9);
+//         max方法 和min 方法
+
+        System.out.println("集合当中最大值:"+Collections.max(list1));
+        System.out.println("集合当中最大值:"+Collections.min(list1));
+
+//         reverse 反转list 集合顺序
+        Collections.reverse(list1);
+        System.out.println(list1);
+
+        // 对于集合进行排序 sort(list)
+        Collections.sort(list1);
+        System.out.println(list1);
+
+        // 有一些业务场景要求我们返回空集合
+        // 3 中方式 1 new ArrayList();  2 Collections.EMP_LIST  3 Collection.emptyList();
+
+        // copy 将一个集合当中元素 复制到另外集合中
+//        List<Integer> list1 = Arrays.asList(1, 3, 10, 4, 9);
+        // 拷贝实收要求新的集合长度要和 之前长度是一样的 , 要对于集合当中元素还有进行初始化
+
+        ArrayList<Integer> list2 = new ArrayList<>(list1.size());
+
+        for (int i = 0; i < list1.size(); i++) {
+            list2.add(null); // 或者使用 0 或其他默认值
+        }
+        System.out.println(list2);
+        Collections.copy(list2,list1);
+        System.out.println(list2);
+    }
+
+    /**
+     * 需求1:  用户输入内容 1,5,6,4,3,2  要求 输出[6,5,4,3,2,1]
+     *
+     * 需求2: 用户输入 10.32 13.00 18.32  8.32 , 要求计算最大值除最小值等于多少要求进行精度计算
+     *
+     * 需求3: 有一个水果有(id,name,color) 在静态代码块中初始化5个水果对象存放到集合中,其中2个绿色,1个红色 ,1个蓝色
+     *       要求在控制台中输入颜色, 要求返回输入颜色水果, 如果不存在返回空集合
+     */
+
+    private static void method3() {
+
+        // 提示: 集合.toArray()  数组
+        // 需求:1  用户在控制台数值类型内容  1,20,3,3,5,6,7
+        // 最终要  数组 [1,3,5,6,7,30]     特点: 去重  - 有顺序
+        // 把大于5的放到 [6,7,30]
+        //==============================================>
+        //1 定义扫描对象
+        Scanner scanner = new Scanner(System.in);
+        //2 遍历7次把输入内容放到set集合中
+        Set<Integer> set = new HashSet<>();
+        for (int i = 0; i < 7; i++) {
+            System.out.println("请输入数组内容:");
+            int count = scanner.nextInt();
+            set.add(count);
+        }
+        //3 把set 集合转换成数组 次数数组是无需的
+        Object[] array =  set.toArray();
+        //4 使用Arrays.sort 进行排序
+        Arrays.sort(array);
+        List<Integer> list = new ArrayList<>();
+        //5 遍历拿到每一个集合中元素
+        for (int i = 0; i < array.length; i++) {
+            //6 判断他是否大于5 , 如果大于5把元素放到一个list 集合中
+            Integer item = (Integer) array[i];
+            //7 把List 集合转成数组
+            if(item>5){
+                list.add(item);
+            }
+        }
+        System.out.println(Arrays.toString(list.toArray()));
+
+
+    }
+
+    private static void method2() {
+        /**
+         * Arrays 当中的一些常见api
+         * 工具类: 主要对数组进行操作
+         * asList  toString  copyeOf  sort
+         */
+        // asList 把数组转换成List 集合
+        List<String> list = Arrays.asList("1", "2", "3");
+        System.out.println(list);
+
+        // toString();  如果不覆盖toString方法 默认打印对象地址值
+        int [] arr = {1,3,2,5,45,6};
+        System.out.println(arr);
+
+        // sort: 对于我们数组进行排序操作
+        Arrays.sort(arr);
+        System.out.println(Arrays.toString(arr));
+
+        // copyOf
+        int[] arr1 = Arrays.copyOf(arr, 10);
+        System.out.println(Arrays.toString(arr1));
+
+    }
+
+    private static void method1() {
+        A a = new A(1,2);
+        System.out.println(CalcUtil.sum(a.getA(), a.getB()));
+
+        B b =new B(2,3);
+        System.out.println(CalcUtil.sum(b.getC(), b.getD()));
+        /**
+         * 抽取工具类有什么好处:  提高代码的复用性
+         * 在写代码的时候一般遵循以一个原则尽量减少重复的代码 DRV 原则
+         *
+         * 自己封装工具类: 自己封装的工具类一般是封装你项目当中的一些重复的代码 或者通用的代码
+         */
+    }
+}

+ 29 - 0
src/main/java/com/sf/day18/_02_util/dt/A.java

@@ -0,0 +1,29 @@
+package com.sf.day18._02_util.dt;
+
+public class A {
+    private Integer a;
+    private Integer b;
+
+    public A(Integer a, Integer b) {
+        this.a = a;
+        this.b = b;
+    }
+
+    public Integer getA() {
+        return a;
+    }
+
+    public void setA(Integer a) {
+        this.a = a;
+    }
+
+    public Integer getB() {
+        return b;
+    }
+
+    public void setB(Integer b) {
+        this.b = b;
+    }
+
+
+}

+ 29 - 0
src/main/java/com/sf/day18/_02_util/dt/B.java

@@ -0,0 +1,29 @@
+package com.sf.day18._02_util.dt;
+
+public class B {
+    private Integer c;
+    private Integer d;
+
+    public Integer getC() {
+        return c;
+    }
+
+    public void setC(Integer c) {
+        this.c = c;
+    }
+
+    public Integer getD() {
+        return d;
+    }
+
+    public void setD(Integer d) {
+        this.d = d;
+    }
+
+    public B(Integer c, Integer d) {
+        this.c = c;
+        this.d = d;
+    }
+
+
+}

+ 54 - 0
src/main/java/com/sf/day18/_02_util/dt/Fruit.java

@@ -0,0 +1,54 @@
+package com.sf.day18._02_util.dt;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Fruit {
+    private Long id;
+    private String name;
+    private String color;
+    public static List<Fruit> fruits = new ArrayList<>();
+
+    // 在静态代码块当中初始化5个水果
+    static {
+        fruits.add(new Fruit(1L,"西瓜","绿色"));
+        fruits.add(new Fruit(2L,"鸭梨","绿色"));
+        fruits.add(new Fruit(3L,"草莓","粉色"));
+        fruits.add(new Fruit(4L,"香蕉","黄色"));
+        fruits.add(new Fruit(5L,"葡萄","紫色"));
+    }
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getColor() {
+        return color;
+    }
+
+    public void setColor(String color) {
+        this.color = color;
+    }
+
+    public Fruit() {
+    }
+
+    public Fruit(Long id, String name, String color) {
+        this.id = id;
+        this.name = name;
+        this.color = color;
+    }
+
+
+}

+ 9 - 0
src/main/java/com/sf/day18/_02_util/util/CalcUtil.java

@@ -0,0 +1,9 @@
+package com.sf.day18._02_util.util;
+
+public class CalcUtil {
+    private CalcUtil(){}
+
+    public static Integer sum(Integer x ,Integer y){
+        return x+y;
+    }
+}

+ 81 - 0
src/main/java/com/sf/day18/_03_exception/Test.java

@@ -0,0 +1,81 @@
+package com.sf.day18._03_exception;
+
+import com.sf.day18._03_exception.dt.Anmail;
+import com.sf.day18._03_exception.dt.Cat;
+import com.sf.day18._03_exception.dt.Dog;
+import com.sf.day18._03_exception.dt.User;
+
+public class Test {
+    public static void main(String[] args) {
+//        method1();
+
+//        method2();
+
+        method3();
+        // 需求:  单独处理空指针异常,打印输入的内容不能为空0 ,
+        //       单独处理除数为0 ,提供用除数不能为0哦
+        //       除此之外其他异常打印系统繁忙亲稍后再试
+    }
+
+    private static void method3() {
+        try{
+//            User user =null;
+//            user.eat();
+//            int i = 1/0;
+            int abc = Integer.parseInt(null);
+        }catch (NullPointerException e){
+            System.out.println("输入的内容不能为空呢");
+        }catch (ArithmeticException e){
+            System.out.println("除数不能为0哦");
+
+        }catch (Exception e){
+            System.out.println("系统繁忙请稍后再试");
+        }
+    }
+
+    /**
+     * try catch
+     */
+    private static void method2() {
+        try{
+            //try  当中去写可能发生异常的代码
+//            int i = 1/0;
+//            int abc = Integer.parseInt("abc");
+//            //出现异常以后 , try 后面代码就无法执行了
+//            System.out.println("2222");
+            Anmail anmail = new Dog();
+            Cat cat = (Cat) anmail;
+            // 参数是要处理异常的类型
+            // 你的cath当中写了什么异常他就只能处理这个异常类型或者是他的子孙后代类型
+
+        }catch (ArithmeticException e){
+            System.out.println("处理除数为0的异常");
+        }catch (NumberFormatException e){
+            System.out.println("字符串格式化异常");
+        }catch (Exception e){
+            System.out.println("处理所有类型异常");
+        }
+        System.out.println("123123");
+        // 我们的程序经过try catch 处理完以后 就不会出现中断的情况了
+    }
+
+    private static void method1() {
+//        int[] arr = {1,2,3,4,5,6,7};
+//        System.out.println(arr[10]);
+        // 当我们程序出现了异常信息, 程序就终端了, 后面的代码就无法执行了
+
+        // NullpointException
+//        User user =null;
+//        user.eat();
+//        System.out.println("123123");
+        // 除数为0异常 ArithmeticException
+//        int i = 1/0;
+        // 格式转换异常 NumberFormatException
+        // 无法将字母转换成数字
+//        int i = Integer.parseInt("abc");
+        // 类型转换异常  ClassCastException
+//        Anmail anmail = new Dog();
+//        Cat cat  = (Cat) anmail;
+
+    }
+}

+ 5 - 0
src/main/java/com/sf/day18/_03_exception/dt/Anmail.java

@@ -0,0 +1,5 @@
+package com.sf.day18._03_exception.dt;
+
+public class Anmail {
+    private String name;
+}

+ 4 - 0
src/main/java/com/sf/day18/_03_exception/dt/Cat.java

@@ -0,0 +1,4 @@
+package com.sf.day18._03_exception.dt;
+
+public class Cat extends Anmail {
+}

+ 4 - 0
src/main/java/com/sf/day18/_03_exception/dt/Dog.java

@@ -0,0 +1,4 @@
+package com.sf.day18._03_exception.dt;
+
+public class Dog extends Anmail {
+}

+ 10 - 0
src/main/java/com/sf/day18/_03_exception/dt/User.java

@@ -0,0 +1,10 @@
+package com.sf.day18._03_exception.dt;
+
+public class User {
+    private String name;
+    private Integer age;
+
+    public void eat(){
+        System.out.println("吃东西");
+    }
+}

+ 104 - 0
src/main/java/com/sf/day19/_01_exception/Test.java

@@ -0,0 +1,104 @@
+package com.sf.day19._01_exception;
+
+import com.sf.day19._01_exception.dt.User;
+import com.sf.day19._01_exception.util.Result;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.util.Scanner;
+
+public class Test {
+    public static void main(String[] args) throws FileNotFoundException {
+//        method1();
+//        method2();
+//        method3();
+//        method9();
+        // 需求: 要在控制台当中打印method4 代码 和 执行后面代码
+//        method4(1,0);
+//        System.out.println("执行后面代码");
+    }
+
+    private static void method9(int num ,int num1) {
+//        User user = null;
+//        user.eat();
+        int ii = num/num1;
+    }
+
+    private static void method4(int num,int num1) throws ArithmeticException {
+        try{
+            method5(num,num1);
+        }catch (ArithmeticException e){
+            e.printStackTrace();
+        }
+        System.out.println("method4代码");
+    }
+
+    private static void method5(int num,int num1) throws ArithmeticException {
+        method6(num,num1);
+        System.out.println("method5代码");
+    }
+    private static void method6(int num, int num1) throws ArithmeticException {
+        int i  = num/num1;
+        System.out.println("method6代码");
+    }
+    private static int method3() {
+        // 验证结论: 如果catch当中有return  , finally 也有return , 返回的时候谁的
+        try{
+            System.out.println("打开一个文件");
+            //如果我们try 当中代码出现了问题, 那文件就无法正常关闭
+            //解决: 使用finally, finally 当中代码最终执行, 不论代码是否出现异常
+            // final 代码是一定会执行的
+            int i =  1/0;
+            return 0;
+        }catch (Exception e){
+            System.out.println("出现了异常信息");
+            e.printStackTrace();
+            return 1;
+        }finally {
+            // 通常情况下都是一些关闭资源的操作, 关闭文件, 关闭连接池
+            System.out.println("关闭文件");
+        }
+    }
+
+    /**
+     * 需求: 在控制台当中输入两个数字: num和num1
+     * 要求对num / num1
+     * 如果代码没有问题 返回 {code:200,msg:"操作成功"}  对象
+     * 如果代码有问题   返回 {code:500,msg: 是出现的异常信息} 对象
+     */
+    private static void method2() {
+        // 1 创建出来一个Scaner 对象
+        Scanner scanner = new Scanner(System.in);
+        System.out.println("请输入除数: ");
+        int num1 = scanner.nextInt();
+        System.out.println("请输入被除数: ");
+        int num2 = scanner.nextInt();
+
+        try{
+            double ret  = num1/num2;
+            System.out.println(new Result(200, "操作成功"));
+        }catch (ArithmeticException e){
+            e.printStackTrace();
+            System.out.println(new Result(500,e.getMessage()));
+        }
+    }
+
+    private static void method1() {
+        try{
+            int abc = Integer.parseInt("abc");
+            System.out.println("123123");
+        }catch (NumberFormatException e) {
+            // 异常对象里面有常用的三个方法 toString(),  getMessage() ,printStackTrace
+//            System.out.println(e.toString());
+//            System.out.println(e.getMessage());
+            // 为了后续在出现bug的时候调试bug 信息我们通常情况下都会打印异常信息和异常位置
+            e.printStackTrace();
+//            System.out.println("字符串在格式化的时候出现了问题");
+        }catch (Exception e){
+            System.out.println("系统繁忙");
+        }
+    }
+
+
+}

+ 93 - 0
src/main/java/com/sf/day19/_01_exception/Test1.java

@@ -0,0 +1,93 @@
+package com.sf.day19._01_exception;
+
+import com.sf.day19._01_exception.able.ILoginAble;
+import com.sf.day19._01_exception.able.impl.LoginAbleImpl;
+import com.sf.day19._01_exception.ex.LoginException;
+import com.sf.day19._01_exception.util.Result;
+import com.sf.day19._01_exception.vo.LoginVO;
+
+import java.util.Scanner;
+
+public class Test1 {
+    public static void main(String[] args) throws IllegalAccessException {
+        /**
+         * 练习  : 定义一个方法 , 方法的参数接收一个数组 , 在方法中遍历数组,对比两种方式:
+         *
+         * - 如果方法接收的数组为null  , 使用打印输出语句提示
+         * - 如果方法接收的数组为null  , 使用抛出异常对象解决
+         */
+//        int [] arr = null;
+//        method1(arr);
+//        try{
+//            method2(arr);
+//        }catch (NullPointerException e){
+//            System.out.println("对于空指针进行处理");
+//        }
+
+        // 用户输入账号和密码以及验证码
+        // 补充: 创建一个LoginVO对象(username,password,code) , 静态代码中初始化一个{"admin","123"."abce"}
+        // 要求1 面相接口编程  login(LoginVo vo);
+        // 要求2 如果username 或者是password 为空抛出NullPointException
+        // 要求3 如果验证码为空 抛出一个空指针异常
+        // 要求4 那用户输入验证码和loginvo 的验证码abce 比较如果不正确throw IllegalArgumentException
+        // 要求4 那用户输入username 和"admin" 密码
+        // 和初始化当中admin 密码也是和初始化对象密码比较账号密码正确在控制台当中输入登录成功,否则登录失败
+        // 要求5 同时要在login 方法上提醒调用者方法可能出现的异常
+
+        // 扩展: 在loginVO 定义一个验证码使用UUID 生成一个6位数的验证码然后存放LoginVO
+        method3();
+    }
+
+    private static void method3() throws IllegalAccessException {
+        // 在控制台当中输入 账号密码和验证码
+        Scanner scanner = new Scanner(System.in);
+        System.out.println("请输入账号: ");
+        String username = scanner.next();
+        System.out.println("请输入密码: ");
+        String password = scanner.next();
+        System.out.println("请输入验证码: ");
+        String code = scanner.next();
+        ILoginAble loginAble = new LoginAbleImpl();
+
+        // 需求: 要在上午案例基础修改
+        //      要求1 方法内部要抛出自定义异常
+        //      要求2 如果输入信息为空 {code:500,msg:"参数不能为空"}
+        //      要求3 如果输入验证码错误{code:500,msg: "验证码错误"}
+        //      要求4 如果输入账号密码错误{code:500,msg: "账号密码错误"}
+        //      要求4 如果输入账号密码正确{code:200,msg;"操作成功"}
+        try{
+            loginAble.login(new LoginVO(username,password,code));
+            System.out.println(new Result(200,"操作成功"));
+        }catch (LoginException e){
+            e.printStackTrace();
+            System.out.println(new Result(500,e.getMessage()));
+        }
+    }
+
+    private static void method1(int[] arr) {
+        // throw new 异常类型 ,  throw new NullPointException();
+        // 第一种情况如果出现为空情况
+        if(arr == null){
+            System.out.println("数组为空");
+            return;
+        }
+
+        for (int i = 0; i < arr.length; i++) {
+            System.out.println(arr[i]);
+        }
+    }
+
+    private static void method2(int[] arr) {
+        // throw new 异常类型 ,  throw new NullPointException();
+        // 第一种情况如果出现为空情况
+        // 1 知道出现了错误 , 错误信息更加详细
+        // 2 在调用者哪也可以提前使用trycatch处理异常信息
+        if(arr == null){
+            throw new NullPointerException();
+        }
+
+        for (int i = 0; i < arr.length; i++) {
+            System.out.println(arr[i]);
+        }
+    }
+}

+ 28 - 0
src/main/java/com/sf/day19/_01_exception/Test2.java

@@ -0,0 +1,28 @@
+package com.sf.day19._01_exception;
+
+import com.sf.day19._01_exception.ex.AgeException;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.util.Scanner;
+
+public class Test2 {
+
+    public static void main(String[] args) throws FileNotFoundException, IllegalAccessException {
+
+//        需求:定义一个年龄的异常,当年龄值不在[1,100]这个范围,程序抛出年龄异常。
+        // 在控制台当中去输入年龄
+        Scanner scanner = new Scanner(System.in);
+        System.out.println("请输入年龄:");
+        int age = scanner.nextInt();
+        method1(age);
+
+    }
+
+    private static void method1(Integer age)  {
+        // 判断年龄是否在1-100 去年
+        if(!(age >=1 && age<=100)){
+            throw new AgeException("年龄不符合标准请输入1-100之内");
+        }
+    }
+}

+ 7 - 0
src/main/java/com/sf/day19/_01_exception/able/ILoginAble.java

@@ -0,0 +1,7 @@
+package com.sf.day19._01_exception.able;
+
+import com.sf.day19._01_exception.vo.LoginVO;
+
+public interface ILoginAble {
+    void login(LoginVO vo) throws IllegalAccessException;
+}

+ 34 - 0
src/main/java/com/sf/day19/_01_exception/able/impl/LoginAbleImpl.java

@@ -0,0 +1,34 @@
+package com.sf.day19._01_exception.able.impl;
+
+import com.sf.day19._01_exception.able.ILoginAble;
+import com.sf.day19._01_exception.ex.LoginException;
+import com.sf.day19._01_exception.vo.LoginVO;
+
+import java.io.File;
+
+public class LoginAbleImpl implements ILoginAble {
+
+    @Override
+    public void login(LoginVO vo) throws IllegalAccessException,NullPointerException {
+        // 要求2 如果username 或者是password 为空抛出NullPointException
+        // 要求3 如果验证码为空 抛出一个空指针异常
+        if(vo.getUsername() == null || vo.getPassword() == null || vo.getCode() == null){
+            throw new LoginException("账号或者密码或者是验证码不能为空");
+        }
+        // 要求4 那用户输入验证码和loginvo 的验证码abce 比较如果不正确throw IllegalArgumentException
+        if(!LoginVO.vo.getCode().equalsIgnoreCase(vo.getCode())){
+            throw new LoginException("验证码错误");
+        }
+        // 要求4 那用户输入username 和"admin" 密码
+        // 和初始化当中admin 密码也是和初始化对象密码比较账号密码正确在控制台当中输入登录成功,否则登录失败
+        String username = LoginVO.vo.getUsername();   //admin
+        String password = LoginVO.vo.getPassword();   //123
+        if(username.equalsIgnoreCase(vo.getUsername()) && password.equalsIgnoreCase(vo.getPassword())){
+            System.out.println("登录成功");
+        }else{
+//            System.out.println("登录失败");
+            throw new LoginException("账号或者是密码错误");
+        }
+        // 要求5 同时要在login 方法上提醒调用者方法可能出现的异常
+    }
+}

+ 7 - 0
src/main/java/com/sf/day19/_01_exception/dt/User.java

@@ -0,0 +1,7 @@
+package com.sf.day19._01_exception.dt;
+
+public class User {
+    public void eat(){
+
+    }
+}

+ 10 - 0
src/main/java/com/sf/day19/_01_exception/ex/AgeException.java

@@ -0,0 +1,10 @@
+package com.sf.day19._01_exception.ex;
+
+public class AgeException extends RuntimeException {
+    public AgeException() {
+    }
+
+    public AgeException(String message) {
+        super(message);
+    }
+}

+ 18 - 0
src/main/java/com/sf/day19/_01_exception/ex/LoginException.java

@@ -0,0 +1,18 @@
+package com.sf.day19._01_exception.ex;
+
+/**
+ * 这个类现在时异常类吗?  不是
+ * 怎样才能让他变成一个异常类 , extends RuntimeException  成为运行时异常
+ */
+public class LoginException extends RuntimeException{
+    public LoginException() {
+    }
+
+    /**
+     * 有参数构造器参数
+     * @param message: 异常信息 , 比如账号密码错误, 比如验证码错误
+     */
+    public LoginException(String message) {
+        super(message);
+    }
+}

+ 19 - 0
src/main/java/com/sf/day19/_01_exception/util/Result.java

@@ -0,0 +1,19 @@
+package com.sf.day19._01_exception.util;
+
+public class Result {
+    private Integer code;
+    private String msg;
+
+    @Override
+    public String toString() {
+        return "Result{" +
+                "code=" + code +
+                ", msg='" + msg + '\'' +
+                '}';
+    }
+
+    public Result(Integer code, String msg) {
+        this.code = code;
+        this.msg = msg;
+    }
+}

+ 44 - 0
src/main/java/com/sf/day19/_01_exception/vo/LoginVO.java

@@ -0,0 +1,44 @@
+package com.sf.day19._01_exception.vo;
+
+public class LoginVO {
+    private String username;
+    private String password;
+    private String code;
+
+    public String getUsername() {
+        return username;
+    }
+
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public LoginVO(String username, String password, String code) {
+        this.username = username;
+        this.password = password;
+        this.code = code;
+    }
+
+    public static LoginVO vo;
+
+    static {
+        vo = new LoginVO("admin","123","abce");
+    }
+
+}

+ 123 - 0
src/main/java/com/sf/day19/_02_file/_01_file_api/TestFileApi.java

@@ -0,0 +1,123 @@
+package com.sf.day19._02_file._01_file_api;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Scanner;
+
+public class TestFileApi {
+
+    public static void main(String[] args) throws IOException {
+//        method1();
+//        method2();
+        method3();
+    }
+
+    // 需求2:
+    // 在d:\\aa 有 4文件 a.txt  b.txt  acc.txt  d.txt要求吧名字当中有a 文件删除掉
+    private static void method3() {
+        //1 获取d:\\aa 目录所有内容  listFiles();
+        File file = new File("d:\\aa");
+        File[] files = file.listFiles();
+        //2 遍历数组拿到每一个File
+        for (File file1 : files) {
+            //3 获取file 路径
+            //file.getName  如果这个file 是一个文件获取就是文件的名字
+            //如果一个路径获取就是他的绝对路径
+            String path = file1.getName();
+            //4 判断路径当中是否包含a
+            if(path.contains("a")){
+                file1.delete();
+            }
+        }
+    }
+    // 需求1
+    // 要求控制台当中输入 路径信息 如果输入 abc  要就在D:\\abc\\abc
+    //                          如果输入的内容已经存在了就提醒用户已存在请修改路径
+    //                          如果输入的a.txt  那就在D:\\abc\\a.txt
+
+
+    // 需求3:  有D:\\abc   这个目录下面有 a目录 ,b.txt ,c.txt   ,a目录当中还有cc.txt
+    //  要打印出abc 目录当中所有的路径保存子目录的路径
+    private static void method2() throws IOException {
+        //1 在控制台当中输入路径
+        Scanner scanner = new Scanner(System.in);
+        System.out.println("请输入路径");
+        //2 创建File 对象
+        String path = scanner.next();
+        String filePath = "D:\\abc\\" + path;
+//        System.out.println(filePath);
+        File file = new File(filePath);
+//        System.out.println(file.getAbsolutePath());
+        //3 调用file.exists() 判断是否存在
+        if(file.exists()){
+            System.out.println("文件已经存在请修改路径");
+            return;
+        }
+
+        String absolutePath = file.getAbsolutePath();
+        if(!absolutePath.contains(".")){
+            file.mkdirs();
+        }{
+            file.createNewFile();
+        }
+
+        //4 判断他是目录还是文件, 如果是目录就创建目录u,如果是文件就创建文件
+        // 问题: file.isDirectory 只能够去判断磁盘当中存在的目录
+        // 思路: 一般文件是有后缀 .java .txt  .html
+        // isDirectory 如果在磁盘当中不论存不存在都能判断
+        // 但是发现他只能够判断磁盘当中存在的目录, 不存在他无法判断
+        /**
+         * 解决思路: 既然他无法帮我们去判断我们输入的内容是一个目录还是一个文件
+         * 那我就要自己想办法去判断输入的内容是目录还是文件
+         * 我知道 目录是没有后缀.txt   文件是有后缀
+         *
+         * 想到了api: indexOf  contains 都可以判断字符串当中是否包含某一个内容,
+         * 判断你的字符串是否包含. ,如果包含. 表示他是一个文件, 如果不包含表示他是一个目录
+         */
+
+    }
+
+
+    private static void method1() throws IOException {
+        // 如何创建一个File的类 , 这个类有没有提供无参数构造器
+        File file = new File("D:\\abc\\a.txt");
+        // 默认他打印就是文件的路径
+        System.out.println(file);
+        // 创建一个文件 createNewFile();
+        // 在abc 目录当中伴我们创建一个a.txt文件
+//        file.createNewFile();
+        // 获取getName 返回值也是路径
+        String name = file.getName();
+        System.out.println(file);
+        // 判断当前路径是否是一个目录
+        System.out.println(file.isDirectory());
+        // 判断当前路径是否是一个文件
+        System.out.println(file.isFile());
+        // 判断当前路径文件获目录是否存在
+        System.out.println(file.exists());
+        // 创建目录的操作 mkdir
+        // D:\abc\caa  mkdir 只能够创建一层
+        File file1 = new File("D:\\abc\\caa\\acc");
+//        file1.mkdir();
+        // mkdirs 创建层级目录
+        file1.mkdirs();
+        // 获取文件绝对路径
+        // 绝对路径                      相对路径
+        // 绝对路径就是这个文件的完整路径
+        File file2 = new File("TestFileApi.java");
+        String absolutePath = file2.getAbsolutePath();
+        System.out.println(absolutePath);
+
+        // 列举目录当中所有内容api
+        File file3 = new File("D:\\abc");
+        File[] files = file3.listFiles();
+        System.out.println(Arrays.toString(files));
+
+        //file 当中提供了delete 方法可以帮我们删除文件
+        File file4 = new File("D:\\abc\\a.txt");
+        file4.delete();
+
+
+    }
+}