次のコードを実行すると、a:28 (コメント内) でファイルが見つからないというエラーが発生します。ディレクトリが更新されていないか、a:28 の行を実行する前にサブプロセスによってファイルが作成されていないためですか?
File outputFile = new File("RunstatsCmd.db2");
FileWriter out = new FileWriter(outputFile);
String cmd = "DB2CMD;DB2;"+" EXPORT TO "+ "\"C:\\file.xml\"" +" OF IXF MESSAGES "+"\"C:\\msg.txt\""+" SELECT * FROM OLTP.ACCOUNT_DETAILS";
out.write("CONNECT TO OLTPDB;\n");
out.write(cmd + ";\n");
out.write("CONNECT RESET;\n");
out.close();
System.out.println("before creating connection....");
Class.forName ("com.ibm.db2.jcc.DB2Driver").newInstance ();
Process p = Runtime.getRuntime().exec("db2 -vtf RunstatsCmd.db2");
// open streams for the process's input and error
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
String s;
// read the output from the command and set the output variable with
// the value
while ((s = stdInput.readLine()) != null)
{
System.out.println(s);
}
// read any errors from the attempted command and set the error
// variable with the value
while ((s = stdError.readLine()) != null)
{
System.out.println(s);
}
// destroy the process created
// delete the temporary file created
outputFile.deleteOnExit();
System.out.println("query executed...");
p.waitFor();
//a:28////////////////////////
FileInputStream fis=new FileInputStream("C:\\file.xml");
int i;
while((i=fis.read())!=-1){
System.out.println((char)i);
}
}catch(Exception e){
e.printStackTrace();
}