Hi All,
i want to close all exe that are open from my java application.
For Example:
if i open
- abc.doc
- gty.txt
- kju.pdf
i want that when i close my application all these exe should be closed.
Please help..
thanks in advance..
Printable View
Hi All,
i want to close all exe that are open from my java application.
For Example:
if i open
- abc.doc
- gty.txt
- kju.pdf
i want that when i close my application all these exe should be closed.
Please help..
thanks in advance..
What do you mean byYou list what I guess are the names of files.Quote:
all exe that are open from my java application
Does your program start a separate Process to "open" each of these files?
Look at the API doc for Runtime and Process to see if there are any methods to do what you want.
here i not using any process, i use the following command to open the file
Runtime run = Runtime.getRuntime();
Process pp=run.exec("C:\\Windows\\notepad.exe"+" abc.dat");
I use this so that i can open more than one file at a time but i dont how to close these file/s.
For example if i open
1) abc.dat
2) xyz.dat
3) sdf.dat
and after working on this i want to close xyz.dat, then how can i achieve this..
Please help..
Thanks
pp.destroy();
Close or kill notepad? The java program doesn't communicate with the notepad program to be able to tell it to close itself.Java does not have the file open, so I don't see how java can close the file. Either the user must click on the close button or you could use the Robot class to click on the close button. That'd be VERY tricky but might be doable.Quote:
i want to close xyz.dat
This works for me, but it doesn't prompt to save any changes typed during the 5 seconds that Notepad is open.dbCode:import java.io.IOException;
public class CloseExe {
public static void main(String[] args) {
try {
ProcessBuilder builder = new ProcessBuilder("Notepad.exe", "e:\\test.txt");
Process process = builder.start();
Thread.sleep(5000);
process.destroy();
} catch (InterruptedException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
Thanks for you reply,
Ya it works for closing the file.
But in my program i dont want to run any process actually, thats why i only use Run command.
because if i am running a process , then at a time i can open only one file but i want to open different files and do the job .
thats why i want to close all the running application when i am exiting from the java application.
Please help.
in simple i want to close all the application which are running
import java.io.IOException;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class CloseExe {
public CloseExe()
{
JFrame f1=new JFrame("Open");
JPanel p1=new JPanel();
f1.getContentPane().add(p1);
JButton b1=new JButton("Open ABC.txt");
JButton b2=new JButton("Open XYZ.txt");
JButton b3=new JButton("Open SDF.txt");
p1.add(b1);
p1.add(b2);
p1.add(b3);
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent er)
{
try
{
Runtime run = Runtime.getRuntime();
Process pp=run.exec("C:\\Windows\\notepad.exe"+" d:\\abc.txt");
}
catch (Exception e)
{
e.printStackTrace();
System.out.println(e.getMessage());
}
}
});
b2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent er)
{
try
{
Runtime run = Runtime.getRuntime();
Process pp=run.exec("C:\\Windows\\notepad.exe"+" d:\\xyz.txt");
}
catch (Exception e1)
{
e1.printStackTrace();
System.out.println(e1.getMessage());
}
}
});
b3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent er)
{
try
{
Runtime run = Runtime.getRuntime();
Process pp=run.exec("C:\\Windows\\notepad.exe"+" d:\\sdf.txt");
}
catch (Exception e2)
{
e2.printStackTrace();
System.out.println(e2.getMessage());
}
}
});
f1.setVisible(true);
f1.setSize(300,300);
f1.show();
}
public static void main(String[] args)
{
new CloseExe();
}
}
Now, open all the notepads.
what i want to do is.
when i click on "X" button in the Java Application (Exiting the application) all the notepad should also be closed.
Please help..
WindowListener#windowClosing
db
ya, but how to close that files??????
Where is the file you want to close?
If in the java program then use the close() method.
If in another program, you have to tell that other program to do the close. The only why I know to have the other program close is to send a message from the java program to the user(a person) telling him/her to close the other program.
You might be able to do it with the Robot class, but it would be very difficult.
It is solved successfully..
i simply set different name for a different process and destroy the processes in window closing event.
Thanks to all of you...:)