Opening a .txt file from an application
I have an application that extends JFrame. There is a JButton that I want to use to open a file called
"Instructions.txt."
and the path to the file is
"E:\CM0112\Code\Instructions.txt".
I want to open this file using TextPad, I have tried the code
Runtime.getRuntime.().exec()
but I keep getting compile errors. Any hints would be greatly appreciated.
[395 byte] By [
Satchya] at [2007-11-26 18:37:48]

import java.io.*;
public class Example {
public static void main(String[] args) throws IOException {
String[] v = {"cmd.exe", "/c", "start", "TextPad.exe", "E:\\CM0112\\Code\\Instructions.txt"};
Runtime.getRuntime().exec(v);
}
}
try this code
public class Open
{
public static void main(String[] args)
{
String line;
EasyReader inFile = new EasyReader("instructions.txt")
if(inFile.bad())
{
System.out.println(" *** Can't Open instructions.txt *** ");
System.exit(1);
}
while((line = inFile.readLine()) != null)
{
//implement your own code, each time loop executes
//line is the next line in the file until it is null.
....
}
}
}
Go to www.rfrank.net/cs-labs/1400-tasmania/EasyReader.java to find EasyReader.java