Merge pull request '2025-10-08 23:03 乔毅凡合并' (#3) from qiaoyifan_branch into develop
commit
23e8359e3a
@ -0,0 +1,43 @@
|
||||
package Service;
|
||||
|
||||
import Base.Question;
|
||||
|
||||
import java.io.*;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class Deal_file {
|
||||
private static final String BASE_DIR="试卷/";
|
||||
|
||||
public Deal_file() {
|
||||
File baseDir = new File(BASE_DIR);
|
||||
if (!baseDir.exists()) {
|
||||
if (!baseDir.mkdirs())
|
||||
System.out.println("目录创建失败!");
|
||||
}
|
||||
}
|
||||
|
||||
public void savePaper(ArrayList<Question> paper, String username) {
|
||||
String userDirPath = BASE_DIR + username + "/";
|
||||
File userDir = new File(userDirPath);
|
||||
if (!userDir.exists()) {
|
||||
if (!userDir.mkdirs()) {
|
||||
System.out.println("目录创建失败!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
String timestamp = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date());
|
||||
String filePath = userDirPath + timestamp + ".txt";
|
||||
|
||||
try (PrintWriter writer = new PrintWriter(new FileWriter(filePath))) {
|
||||
for (int i = 0; i < paper.size(); i++) {
|
||||
writer.println(paper.get(i).toString());
|
||||
if (i < paper.size() - 1) {
|
||||
writer.println();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.out.println("保存文件出错: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue