RUNNING EXE FILE
FROM JAVA AND READ ITS EXE RESULT VALUES:
public void commonProcess() throws IOException,
InterruptedException, ClassNotFoundException, SQLException
{
dt=dateChooserCombo1.getText();
Impvar
vr=dbDate();
int
maxid=vr.max+1;
String
max=String.valueOf(maxid);
ProcessBuilder pb = new
ProcessBuilder("C:\\Users\\user\\Documents\\Visual Studio
2010\\Projects\\Nutri\\Nutri\\bin\\Debug\\Nutri","o",max,dt);
Process ps
= pb.start();
int
exitValue=ps.waitFor();
BufferedReader reader;
// System.out.println("Exit
Value" + exitValue);
if (exitValue == 0) {
reader = new
BufferedReader(new InputStreamReader(ps
.getInputStream()));
} else {
reader = new
BufferedReader(new InputStreamReader(ps
.getErrorStream()));
}
StringBuilder sb = new StringBuilder();
String temp = reader.readLine();
while (temp != null)
{
sb.append(temp);
temp =
reader.readLine();
}
reader.close();
String
stat=sb.toString().trim();
if(stat.equalsIgnoreCase("Opened"))
{
JOptionPane.showMessageDialog(rootPane, "SECTION OPENED FOR
DATE..."+dt);
}
else
{
JOptionPane.showMessageDialog(rootPane, "Execution ERROR...");
System.out.println(stat);
}
}
DISPLAY ANY DOCUMENTS
IN JAVA(.txt,.pdf,.doc,.docx..etc)
private static void
display_File(String filename)
{
try {
if ((new
File(filename+".pdf")).exists()) {
Process p = Runtime
.getRuntime()
.exec("rundll32 url.dll,FileProtocolHandler
"+filename+".pdf");
p.waitFor();
} else {
// System.out.println("File does not
exist");
JOptionPane.showMessageDialog(null,"File does not exist" );
}
}
catch
(Exception ex)
{
ex.printStackTrace();
}
}
NOTE:-CHANGE EXTENSION ACCORDING
TO USAGE TYPE
No comments:
Post a Comment