【发布时间】:2022-11-26 14:42:53
【问题描述】:
我创建了一个函数来创建课堂。现在我想将创建的类的信息保存在一个类名相同的文件中,例如:
我想创建一个带有数学名称的班级,该班级将教室的信息(包括教室容量和教室名称)存储在一个 txt 文件中。
public void createclass(String name,int capacity){
System.out.println("class created !!!");
try {
File [The name we chose for the class]= new File("E:\\[The name we chose for the class].txt");
String str ="class "+name+" "+"with "+capacity+" capacity"+"was created";
FileWriter fileWriter=new FileWriter([our file name]);
fileWriter.write(str);
fileWriter.close();
}
catch (Exception e){
System.out.println(e);
}
}
【问题讨论】:
标签: java