我写了一个java project,里面写了一个批处理文件,比如叫tidy.bat,写一些语句保存到这个文件中,用的FileWriter类,(无法指定保存路径),可是我怎么能打开或保存这个文件呢?
我把里面的程序打成了一个jar包,对吗?然后该怎么做呢?
麻烦告知一下下,谢谢了~~~
------解决方案--------------------
public static void main(String[] args) {
Runtime rn = Runtime.getRuntime();
Process p = null;
try {
FileWriter writer = new FileWriter( "c:\\mysql.bat ");
writer.write( "@echo off ");
writer.write( "\r\n ");
writer.write( "cd C:\\program files\\mysql\\bin\\ mysql -uroot -proot ");
writer.write( "\r\n ");
writer.write( "use database ");
writer.write( "\r\n ");
writer.write( "@echo on ");
writer.close();
p = rn.exec( "cmd /C " + "c:\\mysql.bat ");
} catch (Exception e1) {
e1.printStackTrace();
}
}
最好是动态的生成文件和动态的去执行,你参考一下上面的例子