Здравствуйте, Balu77, Вы писали:
B>A mogno nemnogo podrobnee racpicat,a to ia neo4en poniala...(doctato4no tolko dlia OC Windows) Naprimer ecli pri nagatie na knopky dolgen otkruvatcia tekctovuu faul v bloknote.
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.*;
public class TestOpenByWindows {
public static void main(String[] args) throws FileNotFoundException {
final File file = new File(System.getProperty("java.io.tmpdir"), "myFile.txt");
PrintWriter writer = new PrintWriter(new FileOutputStream(file));
try {
writer.println("Hello Notepad!");
} finally {
writer.close();
}
final JFrame frame = new JFrame("Text open");
frame.getContentPane().add(
new JButton(
new AbstractAction("Open ME!") {
public void actionPerformed(ActionEvent actionEvent) {
try {
Runtime.getRuntime().exec(new String[] {"cmd.exe", "/C", "start", file.getAbsolutePath()});
} catch (IOException e) {
JOptionPane.showMessageDialog(frame, String.valueOf(e), "IO error", JOptionPane.ERROR_MESSAGE);
}
}
}
)
);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}