Java from entry to master chapter exercises - Chapter 15
Exercise 1 outputs the Java code written by this class
Comprehensive exercise 1: Output the Java code written in this class Create a MyReader class, write code in this class to read all the codes in the file of this class, and output these codes to the console.
package org.hj.chapter15;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class MyReader {
public static void main(String[] args) {
try {
// 使用 BufferedReader 读取本类文件
BufferedReader reader = new BufferedReader(new FileReader("D:\\IdeaProject\\exercise\\JavaBaseExercise\\src\\main\\java\\org\\hj\\chapter15\\MyReader.java"));
String line;
// 逐行读取并输出
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
//关流!!!
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Exercise 2 records all file/folder names
Comprehensive exercise 2: Record all file/folder names Save all file/folder names in the Windows folder of the C drive in a text file.
I tried to increase the width occupied by the desktop icons, and it was solved after restarting. This exercise will be avoided (manual dog head).
不要乱搞