|
//== Read a text-file == // Reads the contents of a text-file, and displays the contents //======================================================================= import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; public class ReadFile extends EasyApp // EasyApp contains IBIO // + standard constructor stuff { public static void main(String[] args) { new ReadFile(); } // Instantiate an object = start program List display = addList("",20,30,550,350,this); // create a list box for display public ReadFile() { String filename = input("File Name"); try { BufferedReader file = new BufferedReader(new FileReader(filename)); // open file for reading String info = ""; display.removeAll(); // clear display list while (file.ready()) // stops at end-of-file { info = file.readLine(); // read a line of text display.add(info); // put text into display list } file.close(); // close file } catch (IOException e) // handle IO errors, such as { output(e.toString()); } // file-not-found } } |