IO

image.png

案例:创建文件在里面写东西

  1. package com.zhsj.mybatis.test;
  2. import java.io.*;
  3. import java.nio.charset.StandardCharsets;
  4. import java.util.ArrayList;
  5. import java.util.Scanner;
  6. /**
  7. * @program: test
  8. * @description:
  9. * @author: liulq
  10. * @create: 2022-03-13 20:55
  11. */
  12. public class Day2 {
  13. public static void main(String[] args) throws IOException {
  14. File targFile =createFile();
  15. writerFile(targFile);
  16. System.out.println("结束");
  17. }
  18. private static void writerFile(File targFile) throws IOException {
  19. try (
  20. FileOutputStream fileOutputStream = new FileOutputStream(targFile);
  21. OutputStreamWriter f = new OutputStreamWriter(fileOutputStream, StandardCharsets.UTF_8);
  22. PrintWriter pw = new PrintWriter(f);
  23. ){
  24. while (true){
  25. Scanner scanner = new Scanner(System.in);
  26. String line = scanner.nextLine().trim();
  27. System.out.println("输入的内容为"+line);
  28. if (line.trim().isBlank()){
  29. System.out.println("输入结束");
  30. break;
  31. }else {
  32. pw.println(line);
  33. pw.flush();
  34. }
  35. }
  36. }catch (IOException e) {
  37. e.printStackTrace();
  38. }
  39. }
  40. private static File createFile() throws IOException {
  41. System.out.println("输出文件名");
  42. Scanner scanner = new Scanner(System.in);
  43. String fileName =scanner.nextLine().trim();
  44. File f= new File("."+File.separator+fileName+".txt");
  45. if (f.isFile()){
  46. System.out.println("目录文件存在,删除"+f.delete());
  47. }
  48. System.out.println(f.createNewFile());
  49. return f;
  50. }
  51. }

网络通讯

image.png

image.png
image.png

线程

image.pngimage.png

concurrent

image.png

image.png

image.png