每当我在代码中调用方法时,尽管正确打开和关闭了BufferedWriter(我认为),它仍然拒绝打印到要打印到的文本文件中
这是我的代码:
public Student(String nameInput, String gradeInput) throws IOException
{
BufferedWriter o = new BufferedWriter(new FileWriter("Students.txt"));
name = nameInput;
grade = gradeInput;
o.write(gradeInput);
o.newLine();
o.write(nameInput);
o.close();
}
最佳答案
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
public class Main {
public static void Student(String nameInput, String gradeInput) throws IOException
{
BufferedWriter o = new BufferedWriter(new FileWriter("Students.txt"));
String name = nameInput;
String grade = gradeInput;
o.write(gradeInput);
o.newLine();
o.write(nameInput);
o.close();
}
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Student("ABC","A");
}
}
关于java - bufferedwriter拒绝写入文本文件(Java),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54283793/