execute file from a file dialogue
JButton openButton =new JButton ("Open File");
openButton.addActionListener (new ActionListener ()
{
publicvoid actionPerformed (ActionEvent e)
{
int returnVal = fc.showOpenDialog (Interface.this);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
File file = fc.getSelectedFile ();
log.append ("Opening: " + file.getName ());
- - ->> problem is from here.....
}
else
{
log.append ("File not opened\n");
}
}
}
);
after compiled, the textarea only display "Opening (the file i clicked from the file dialogue)" so how do i display the sentence "Opening (the file i clicked from the file dialogue)" and alsoexecute the file i clicked from the file dialogue?
thanks
jp
The filechooser demo code from the sun tutorials did not include the file i/o code. Instead it said "//This is where a real application would open the file."
I recommend that you look at the swing i/o tutorials to learn how to open, read, write to, and close files. You can find it [url=http://java.sun.com/docs/books/tutorial/essential/io/index.html]here[/url]. Good luck.
/Pete
JButton openButton = new JButton ("Open File");
openButton.addActionListener (new ActionListener ()
{
public void actionPerformed (ActionEvent e)
{
int returnVal = fc.showOpenDialog (Interface.this);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
File file = fc.getSelectedFile ();
log.append ("Opening: " + file.getName ());
is this following code below- - - - - - - - - - - -
try {
Runtime.getRuntime().exec("cmd /c start" +file);
}
catch (Exception x) {
x.printStackTrace();
}
catch (Error e) {
e.printStackTrace();
}
- - - - - - - - -able to execute the file i chose?
else
{
log.append ("File not opened\n");
}
}
}
);
after compiled, the textarea only display "Opening (the file i clicked from the file dialogue)" so how do i display the sentence "Opening (the file i clicked from the file dialogue)" and also execute the file i clicked from the file dialogue?
is the additional code correct?
thanks
jp