Opening files in java seems a bit complicated - for .txt files, you must use the File object in combination with the Scanner or BufferedReader object - you need to use the ImageIcon class to enter IO images - and if one of them literally opens a .txt document (it looks like double-clicking on the application ) from java, this code works:
import java.io.*; public class LiterallyOpenFile { public static void main(String[] args) throws IOException { Runtime rt = Runtime.getRuntime(); Process p = rt.exec("notepad Text.txt"); } }
I'm not sure, but I think that other file types / names can be replaced in brackets after exec. In any case, I plan to open certain files in JFileChooser when the user clicks on the file to be opened (when the user clicks on the file, the path to the file can be obtained using the getSelectedFile () method). Although I'm more specifically looking for the opportunity to open an Arduino file in an Arduino environment from a Java program, for example, a simulated double-click .. maybe something like this?
import java.io.*; public class LiterallyOpenFile { public static void main(String[] args) throws IOException { Runtime rt = Runtime.getRuntime(); Process p = rt.exec("Arduino C:\\Arduino\\fibonacci_light\\fibonacci_light.ino"); } }
A point in the right direction would be appreciated.
source share