8.13
1.创建文件、重命名、删除、添加内容
package com.zhongruan.test;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class TextFile {
public static void main(String[] args) throws IOException {
//1.创建文件aaa.txt
File file = new File(“D:\文件.Java\aaa.txt”);
file.createNewFile();
//6.在aaa.txt文件中写上: hello 我好开心,作业很少
FileWriter writer = new FileWriter(file, true);
writer.write(“hello 我好开心,作业很少”);
writer.close();
//2.重命名bbb.txt
File file1 = new File(“D:\文件.Java\bbb.txt”);
file.renameTo(file1);
System.out.println(file);
//3.删除bbb.txt
file1.delete();
}
}
2.jdb实现增加、删除、修改、查找
package com.zhongruan.util;
import java.sql.*;
public class DButil {
public static Connection getConnection(){
Connection connection = null;
//1.加载驱动
try {
Class.forName(“com.mysql.jdbc.Driver”);
//2.创建连接
connection = DriverManager.getConnection
(“jdbc:mysql://127.0.0.1:3306/nbcj?useSSL=true&characterEncoding=utf-8&user=root&password=123456”);
System.out.println(“创建连