cherry/util/exFile/java/ExFile.java

INDEX Java.use(better)
  1: //..+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
  2: /*
  3:  * Copyright (c) 2010-2011, KOTSUBU-chan and/or its affiliates.
  4:  * All rights reserved.
  5:  * @version 1.0
  6:  */ 
  7: package cherry;
  8: 
  9: import java.awt.*;
 10: import java.io.*;
 11: import javax.swing.*;
 12: 
 13: // ----------------------------------------
 14: public class ExFile {
 15:   private RandomAccessFile file;
 16: 
 17:   // ----------------------------------------
 18:   public ExFile(TextView view, String name) {
 19:     this.open(view, name);
 20:     this.show(view);
 21:     this.close();
 22:   }
 23: 
 24:   // ----------------------------------------
 25:   void open(TextView view, String name) {
 26:     try {
 27:       this.file = new RandomAccessFile(name, "r");
 28:     }
 29:     catch (FileNotFoundException e) {
 30:       System.err.println("Error: File Not Found");
 31:       name = "*** File not found ***";
 32:     }
 33:     view.setTitle(name);
 34:   }
 35: 
 36:   void show(TextView view) {
 37:     if (this.file == null) return;
 38: 
 39:     try {
 40:       String line = this.file.readLine();
 41:       while (line != null) {
 42:         view.println(line);
 43:         line = this.file.readLine();
 44:       }
 45:     }
 46:     catch (IOException e) {
 47:       System.err.println("Error: readLine()");
 48:     }
 49:     view.reset();
 50:   }
 51: 
 52:   void close() {
 53:     if (this.file == null) return;
 54: 
 55:     try {
 56:       this.file.close();
 57:     }
 58:     catch (IOException e) {
 59:       System.err.println("Error: close()");
 60:     }
 61:   }
 62: 
 63:   // ----------------------------------------
 64:   private static void ex_File(String name, Dimension d) {
 65:     TextView view = new TextView(name, d);
 66:     view.setFont_(new Font("Courier", Font.PLAIN, 12));
 67:     new ExFile(view, name);
 68:     view.setVisible(true);
 69:   }
 70: 
 71:   // ----------------------------------------
 72:   public static void tips() {
 73:     ex_File(
 74:       "ExFile.java",
 75:       new Dimension(580, 400));
 76:   }
 77: 
 78:   // ----------------------------------------
 79:   ExFile() {}
 80:   static String version = new ExFile()
 81:     .getClass().getName()+": #1.0.09";
 82: }
 83: 
 84: // ========================================