在文件写入字符串

public static void migrationV4SQL(String menuName)   {


try {
RandomAccessFile rf=new RandomAccessFile(getDiskFileItem(),"rw");
rf.seek(rf.length()); //将指针移动到文件末尾
rf.write((BuildMenuUtils.buildSQL(menuName)+" ").getBytes()); //字符串末尾需要换行符
rf.close();//关闭文件流
}catch (IOException e){
e.printStackTrace();
}
//
// try {
// FileOutputStream fos = new FileOutputStream (new File("d:\abc.txt"),true ) ;
// String str = "ABC " ; //字符串末尾需要换行符
// fos.write(str.getBytes()) ;
// fos.close ();
// } catch (IOException e) {
// e.printStackTrace();
// }
//
// try {
// FileWriter fw = new FileWriter("d:\abc.txt",true);
// PrintWriter pw=new PrintWriter(fw);
// pw.println("append content"); //字符串末尾不需要换行符
// pw.close () ;
// fw.close () ;
// } catch (IOException e) {
// e.printStackTrace();
// }
}

public static String getDiskFileItem(){
String root = new StringBuilder(System.getProperty("user.dir"))
.append(File.separator)
.append("src")
.append(File.separator)
.append("main")
.append(File.separator)
.append("java")
.append(File.separator)
.append("db")
.append(File.separator)
.append("migration")
.append(File.separator)
.append("V4__.sql")
.toString();
return root;
}
 
原文地址:https://www.cnblogs.com/Amos-Turing/p/7923243.html