我正在编写一个应用程序。一种功能是从另一种功能创建Excel文件。为了做到这一点,我(从同事那里)有一个可执行的jar文件,该文件读取config.properties文件(都在应用程序的Java项目中)。当我使用cmd时,罐子起作用了。但是当我使用下面的代码时,它说:
Process proc = Runtime.getRuntime().exec("java -jar ADD_Excel_Export\\paces.jar");
proc.waitFor();
InputStream in = proc.getInputStream();
InputStream err = proc.getErrorStream();
byte b[]=new byte[in.available()];
in.read(b,0,b.length);
System.out.println(new String(b));
byte c[]=new byte[err.available()];
err.read(c,0,c.length);
System.out.println(new String(c));
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.io.FileNotFoundException: config.properties (Das System kann die angegebene Datei nicht finden)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:93)
at addSignal.ADDSignalExport.main(ADDSignalExport.java:136)
... 5 more
不可能做我刚刚描述的事情,或者我在某个地方错了?