From 786047512d3e081d07dfb4ef64485128d935c8be Mon Sep 17 00:00:00 2001 From: hnu202326010302 <1677625723@qq.com> Date: Sun, 28 Sep 2025 22:38:43 +0800 Subject: [PATCH] Delete 'src/filemanage.java' --- src/filemanage.java | 93 --------------------------------------------- 1 file changed, 93 deletions(-) delete mode 100644 src/filemanage.java diff --git a/src/filemanage.java b/src/filemanage.java deleted file mode 100644 index 7ff754e..0000000 --- a/src/filemanage.java +++ /dev/null @@ -1,93 +0,0 @@ -import java.io.IOException; -import java.nio.file.FileAlreadyExistsException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardOpenOption; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -public class filemanage { - ArrayList array = new ArrayList<>(); - - public static void main(String[] args) { - filemanage f1 = new filemanage(); - f1.filecreate("张三1", "123"); - f1.fileread("张三1"); - for (String i : f1.array) { - System.out.println(i); - } - f1.filewrite("张三1", "123", "1"); - } - - public static List getFileNames(String str) throws IOException { - Path dirPath = Path.of("User-problem"); - Path filePathf = dirPath.resolve(str); - try (var files = Files.list(filePathf)) { - return files.filter(Files::isRegularFile) - .map(path -> path.getFileName().toString()) // 提取文件名 - .collect(Collectors.toList()); - } - } - - void fileread(String str) { - String readfilef = str; - Path dirPath = Path.of("User-problem"); - Path filePathf = dirPath.resolve(readfilef); - try { - getFileNames(str); - for (String i : getFileNames(str)) { - String readfile = i; - Path filePath = filePathf.resolve(readfile); - try { - List fileLines = Files.readAllLines(filePath); - for (String j : fileLines) { - array.add(j); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - void filewrite(String str, String str1, String str2) { - List newLines = new ArrayList<>(); - newLines.add(str2); - String writefilef = str; - String writefile = str1 + ".txt"; - Path dirPath = Path.of("User-problem"); - Path filePathf = dirPath.resolve(writefilef); - Path filePath = filePathf.resolve(writefile); - try { - Files.write(filePath, newLines, - StandardOpenOption.APPEND); // 追加模式 - } catch (IOException e) { - e.printStackTrace(); - } - } - - void filecreate(String str, String str1) { - String createfilef = str; - String createfile = str1 + ".txt"; - try { - Path dirPath = Paths.get("User-problem"); - if (!Files.exists(dirPath)) { - Files.createDirectories(dirPath); - } - - // 在目录中创建文件 - Path filePathf = dirPath.resolve(createfilef); - Path filePath = filePathf.resolve(createfile); - Files.createFile(filePath); - - } catch (FileAlreadyExistsException e) { - //System.out.println("文件已存在!"); - } catch (IOException e) { - e.printStackTrace(); - } - } -}