我编辑了代码,你能否告诉我如何在文件末尾写下每一行?这里写的是同一条线。你能帮忙吗?
private void okMouseClicked(java.awt.event.MouseEvent evt) {
String pass = name.getText();
if (pass.equals("")){
error.setText("Name of Entity should not be left blank");
//JOptionPane.showMessageDialog(null,"Name of Entity should not be left blank");
}
else{
try{
Formatter outfile = new Formatter(new FileOutputStream("Convert.sql", true));
outfile.format("Create Database IF NOT EXISTS " + pass + ";");
outfile.close();
}
catch(FileNotFoundException fnfe){
System.out.println("Not found");
}
this.dispose();
}
}
答案 0 :(得分:0)
您可以传递给在附加模式中创建的Formatter
和FileOutputStream
的构造函数:
Formatter outfile = new Formatter(new FileOutputStream("Convert.sql", true));
outfile.format("Create Database IF NOT EXISTS " + pass + ";\n"); // \n to add new line
请参阅http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#Formatter(java.io.OutputStream)。