zoukankan      html  css  js  c++  java
  • 在文件写入字符串

    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;
    }
     
  • 相关阅读:
    NYOJ题目916胖子小的百宝袋
    NYOJ题目893十字架
    NYOJ题目874签到
    设计模式之Singleton
    Elo rating system 模拟
    JDBC之SqlHelper
    《Thinking in Java》十四章类型信息_习题解
    NYOJ题目842整除的尾数
    NYOJ题目840吃花生
    NYOJ题目839合并
  • 原文地址:https://www.cnblogs.com/Amos-Turing/p/7923243.html
Copyright © 2011-2022 走看看