我用java调用批处理文件.bat,请问怎么把绝对路径改成相对路径。代码如下:
public void runbat() {
String cmd = "cmd /c start E:/tr/bin/win32/text.bat";
try {
Process ps = Runtime.getRuntime().exec(cmd);
System.out.println(ps.getInputStream());
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
public void runbat() {
String cmd = "cmd /c start E:/tr/bin/win32/text.bat";
try {
Process ps = Runtime.getRuntime().exec(cmd);
System.out.println(ps.getInputStream());
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
select * from t1;
java:String cmd = "cmd /c start ../text.bat";
测试了下好像没有问题!
String cmd = "cmd /c start ./text.bat";
text.bat 放在src目录下,则以下方式
BerylliumSphere.class.getResource("/text.bat") BerylliumSphere 当前执行runbat函数的类名
String cmd=directory.getCanonicalPath()+“text.bat”;获取路径
import java.io.IOException;public class ReadBat { public static void main(String[] args) {
String cmd = "cmd /c start c:/TestJava/text.bat";
try {
Process ps = Runtime.getRuntime().exec(cmd);
System.out.println(ps.getInputStream());
} catch(IOException ioe) {
ioe.printStackTrace();
} }}
改成相对路劲就不行了,坐等楼主答案
Process ps = Runtime.getRuntime().exec("cmd cd ./cityIndexTool /c start CsvToIndex.bat");没成功,
谁能告诉我不放在绝对路径下的方法?????