I know how to write messages and save it as a .txt file (using Input/Output streams). What I want to do now is to be able to click a button and have notepad open the .txt file. How can I do this?

Recommended Answers

All 6 Replies

You can use the Process class to execute OS commands like Notepad.
For code examples use Search here or Google.

Another option is the Desktop.open() method. You have more control with the Process the NormR1 mentioned, but it is OS-specific. The choice depends on your particular needs.

Hi Norm, this is what I was able to find:

Process p = Runtime.getRuntime().exec("notepad.exe ctpublish/numnum.txt");

however this seems to run a thread that won't exit until I close the notepad file, numnum.txt. Is there a way to just have the Process p run and end without me having to shut down notepad?

What does the API doc say?
I don't know if you can end the process if Notepad is still executing?

This is code i use actually to open the browser in windows, and it seems to open notepad with a txt file on my computer.

try {
  Runtime rt = Runtime.getRuntime();

				 String[] cmd = new String[4];
	              cmd[0] = "cmd.exe";
	              cmd[1] = "/C";
	              cmd[2] = "start";
	              cmd[3] = "manifest.txt";

	              rt.exec(cmd);

}
catch(Exception e){}

Adams, thanks for this :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.