<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FFile_Input_Output%2FFileReader</id>
		<title>Java/File Input Output/FileReader - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FFile_Input_Output%2FFileReader"/>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java/File_Input_Output/FileReader&amp;action=history"/>
		<updated>2026-04-18T08:54:51Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://jexp.ru/index.php?title=Java/File_Input_Output/FileReader&amp;diff=6141&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java/File_Input_Output/FileReader&amp;diff=6141&amp;oldid=prev"/>
				<updated>2010-06-01T06:02:46Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 06:02, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://jexp.ru/index.php?title=Java/File_Input_Output/FileReader&amp;diff=6140&amp;oldid=prev</id>
		<title> в 18:01, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java/File_Input_Output/FileReader&amp;diff=6140&amp;oldid=prev"/>
				<updated>2010-05-31T18:01:43Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== An InputStream backed by a Reader ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
 * Java Network Programming, Second Edition&lt;br /&gt;
 * Merlin Hughes, Michael Shoffner, Derek Hamner&lt;br /&gt;
 * Manning Publications Company; ISBN 188477749X&lt;br /&gt;
 *&lt;br /&gt;
 * http://nitric.ru/jnp/&lt;br /&gt;
 *&lt;br /&gt;
 * Copyright (c) 1997-1999 Merlin Hughes, Michael Shoffner, Derek Hamner;&lt;br /&gt;
 * all rights reserved.&lt;br /&gt;
 *&lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions&lt;br /&gt;
 * are met:&lt;br /&gt;
 *&lt;br /&gt;
 * 1. Redistributions of source code must retain the above copyright&lt;br /&gt;
 *    notice, this list of conditions and the following disclaimer.&lt;br /&gt;
 *&lt;br /&gt;
 * 2. Redistributions in binary form must reproduce the above copyright&lt;br /&gt;
 *    notice, this list of conditions and the following disclaimer in&lt;br /&gt;
 *    the documentation and/or other materials provided with the&lt;br /&gt;
 *    distribution.&lt;br /&gt;
 *&lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE ABOVE NAMED AUTHORS &amp;quot;AS IS&amp;quot; AND ANY&lt;br /&gt;
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE&lt;br /&gt;
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR&lt;br /&gt;
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS, THEIR&lt;br /&gt;
 * PUBLISHER OR THEIR EMPLOYERS BE LIABLE FOR ANY DIRECT, INDIRECT,&lt;br /&gt;
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,&lt;br /&gt;
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;&lt;br /&gt;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)&lt;br /&gt;
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,&lt;br /&gt;
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)&lt;br /&gt;
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED&lt;br /&gt;
 * OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 */&lt;br /&gt;
import java.io.ByteArrayOutputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.InputStream;&lt;br /&gt;
import java.io.OutputStreamWriter;&lt;br /&gt;
import java.io.Reader;&lt;br /&gt;
import java.io.UnsupportedEncodingException;&lt;br /&gt;
import java.io.Writer;&lt;br /&gt;
/**&lt;br /&gt;
 * An InputStream backed by a Reader&lt;br /&gt;
 */&lt;br /&gt;
public class ReaderInputStream extends InputStream {&lt;br /&gt;
  protected Reader reader;&lt;br /&gt;
  protected ByteArrayOutputStream byteArrayOut;&lt;br /&gt;
  protected Writer writer;&lt;br /&gt;
  protected char[] chars;&lt;br /&gt;
  protected byte[] buffer;&lt;br /&gt;
  protected int index, length;&lt;br /&gt;
  /**&lt;br /&gt;
   * Constructor to supply a Reader&lt;br /&gt;
   *&lt;br /&gt;
   * @param reader - the Reader used by the InputStream&lt;br /&gt;
   */&lt;br /&gt;
  public ReaderInputStream(Reader reader) {&lt;br /&gt;
    this.reader = reader;&lt;br /&gt;
    byteArrayOut = new ByteArrayOutputStream();&lt;br /&gt;
    writer = new OutputStreamWriter(byteArrayOut);&lt;br /&gt;
    chars = new char[1024];&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Constructor to supply a Reader and an encoding&lt;br /&gt;
   *&lt;br /&gt;
   * @param reader   - the Reader used by the InputStream&lt;br /&gt;
   * @param encoding - the encoding to use for the InputStream&lt;br /&gt;
   * @throws UnsupportedEncodingException if the encoding is not supported&lt;br /&gt;
   */&lt;br /&gt;
  public ReaderInputStream(Reader reader, String encoding) throws UnsupportedEncodingException {&lt;br /&gt;
    this.reader = reader;&lt;br /&gt;
    byteArrayOut = new ByteArrayOutputStream();&lt;br /&gt;
    writer = new OutputStreamWriter(byteArrayOut, encoding);&lt;br /&gt;
    chars = new char[1024];&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * @see java.io.InputStream#read()&lt;br /&gt;
   */&lt;br /&gt;
  public int read() throws IOException {&lt;br /&gt;
    if (index &amp;gt;= length)&lt;br /&gt;
      fillBuffer();&lt;br /&gt;
    if (index &amp;gt;= length)&lt;br /&gt;
      return -1;&lt;br /&gt;
    return 0xff &amp;amp; buffer[index++];&lt;br /&gt;
  }&lt;br /&gt;
  protected void fillBuffer() throws IOException {&lt;br /&gt;
    if (length &amp;lt; 0)&lt;br /&gt;
      return;&lt;br /&gt;
    int numChars = reader.read(chars);&lt;br /&gt;
    if (numChars &amp;lt; 0) {&lt;br /&gt;
      length = -1;&lt;br /&gt;
    } else {&lt;br /&gt;
      byteArrayOut.reset();&lt;br /&gt;
      writer.write(chars, 0, numChars);&lt;br /&gt;
      writer.flush();&lt;br /&gt;
      buffer = byteArrayOut.toByteArray();&lt;br /&gt;
      length = buffer.length;&lt;br /&gt;
      index = 0;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * @see java.io.InputStream#read(byte[], int, int)&lt;br /&gt;
   */&lt;br /&gt;
  public int read(byte[] data, int off, int len) throws IOException {&lt;br /&gt;
    if (index &amp;gt;= length)&lt;br /&gt;
      fillBuffer();&lt;br /&gt;
    if (index &amp;gt;= length)&lt;br /&gt;
      return -1;&lt;br /&gt;
    int amount = Math.min(len, length - index);&lt;br /&gt;
    System.arraycopy(buffer, index, data, off, amount);&lt;br /&gt;
    index += amount;&lt;br /&gt;
    return amount;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * @see java.io.InputStream#available()&lt;br /&gt;
   */&lt;br /&gt;
  public int available() throws IOException {&lt;br /&gt;
    return (index &amp;lt; length) ? length - index :&lt;br /&gt;
        ((length &amp;gt;= 0) &amp;amp;&amp;amp; reader.ready()) ? 1 : 0;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * @see java.io.InputStream#close()&lt;br /&gt;
   */&lt;br /&gt;
  public void close() throws IOException {&lt;br /&gt;
    reader.close();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Create BufferedReader from FileReader and process lines from file ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
import java.io.BufferedReader;&lt;br /&gt;
import java.io.FileReader;&lt;br /&gt;
class Main {&lt;br /&gt;
  public static void main(String args[]) throws Exception {&lt;br /&gt;
    FileReader fr = new FileReader(args[0]);&lt;br /&gt;
    BufferedReader br = new BufferedReader(fr);&lt;br /&gt;
    // Process lines from file&lt;br /&gt;
    String line;&lt;br /&gt;
    while ((line = br.readLine()) != null) {&lt;br /&gt;
      char array[] = line.toCharArray();&lt;br /&gt;
      System.out.print(array[0]);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Read and copy with FileReader and FileWriter ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
import java.io.FileReader;&lt;br /&gt;
import java.io.FileWriter;&lt;br /&gt;
import java.io.Reader;&lt;br /&gt;
import java.io.Writer;&lt;br /&gt;
public class FileReaderWriterExample {&lt;br /&gt;
  public static void main(String[] args) throws Exception {&lt;br /&gt;
    Reader r = new FileReader(&amp;quot;in.txt&amp;quot;);&lt;br /&gt;
    Writer w = new FileWriter(&amp;quot;out.txt&amp;quot;);&lt;br /&gt;
    int c;&lt;br /&gt;
    while ((c = r.read()) != -1) {&lt;br /&gt;
      System.out.print((char) c);&lt;br /&gt;
      w.write(c);&lt;br /&gt;
    }&lt;br /&gt;
    r.close();&lt;br /&gt;
    w.close();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Read characters with FileReader ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
import java.io.FileReader;&lt;br /&gt;
class DigitCounter {&lt;br /&gt;
  public static void main(String args[]) throws Exception {&lt;br /&gt;
    // Create a file reader&lt;br /&gt;
    FileReader fr = new FileReader(args[0]);&lt;br /&gt;
    // Read characters&lt;br /&gt;
    int i;&lt;br /&gt;
    while ((i = fr.read()) != -1) {&lt;br /&gt;
      System.out.println((char) i);&lt;br /&gt;
    }&lt;br /&gt;
    // Close file reader&lt;br /&gt;
    fr.close();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Text file viewer ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 2004 David Flanagan.  All rights reserved.&lt;br /&gt;
 * This code is from the book Java Examples in a Nutshell, 3nd Edition.&lt;br /&gt;
 * It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied.&lt;br /&gt;
 * You may study, use, and modify it for any non-commercial purpose,&lt;br /&gt;
 * including teaching and use in open-source projects.&lt;br /&gt;
 * You may distribute it non-commercially as long as you retain this notice.&lt;br /&gt;
 * For a commercial use license, or to purchase the book, &lt;br /&gt;
 * please visit http://www.davidflanagan.ru/javaexamples3.&lt;br /&gt;
 */&lt;br /&gt;
import java.awt.Button;&lt;br /&gt;
import java.awt.FileDialog;&lt;br /&gt;
import java.awt.FlowLayout;&lt;br /&gt;
import java.awt.Font;&lt;br /&gt;
import java.awt.Frame;&lt;br /&gt;
import java.awt.Panel;&lt;br /&gt;
import java.awt.TextArea;&lt;br /&gt;
import java.awt.event.ActionEvent;&lt;br /&gt;
import java.awt.event.ActionListener;&lt;br /&gt;
import java.awt.event.WindowAdapter;&lt;br /&gt;
import java.awt.event.WindowEvent;&lt;br /&gt;
import java.io.File;&lt;br /&gt;
import java.io.FileReader;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
/**&lt;br /&gt;
 * This class creates and displays a window containing a TextArea, in which the&lt;br /&gt;
 * contents of a text file are displayed.&lt;br /&gt;
 */&lt;br /&gt;
public class FileViewer extends Frame implements ActionListener {&lt;br /&gt;
  String directory; // The default directory to display in the FileDialog&lt;br /&gt;
  TextArea textarea; // The area to display the file contents into&lt;br /&gt;
  /** Convenience constructor: file viewer starts out blank */&lt;br /&gt;
  public FileViewer() {&lt;br /&gt;
    this(null, null);&lt;br /&gt;
  }&lt;br /&gt;
  /** Convenience constructor: display file from current directory */&lt;br /&gt;
  public FileViewer(String filename) {&lt;br /&gt;
    this(null, filename);&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * The real constructor. Create a FileViewer object to display the specified&lt;br /&gt;
   * file from the specified directory&lt;br /&gt;
   */&lt;br /&gt;
  public FileViewer(String directory, String filename) {&lt;br /&gt;
    super(); // Create the frame&lt;br /&gt;
    // Destroy the window when the user requests it&lt;br /&gt;
    addWindowListener(new WindowAdapter() {&lt;br /&gt;
      public void windowClosing(WindowEvent e) {&lt;br /&gt;
        dispose();&lt;br /&gt;
      }&lt;br /&gt;
    });&lt;br /&gt;
    // Create a TextArea to display the contents of the file in&lt;br /&gt;
    textarea = new TextArea(&amp;quot;&amp;quot;, 24, 80);&lt;br /&gt;
    textarea.setFont(new Font(&amp;quot;MonoSpaced&amp;quot;, Font.PLAIN, 12));&lt;br /&gt;
    textarea.setEditable(false);&lt;br /&gt;
    this.add(&amp;quot;Center&amp;quot;, textarea);&lt;br /&gt;
    // Create a bottom panel to hold a couple of buttons in&lt;br /&gt;
    Panel p = new Panel();&lt;br /&gt;
    p.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 5));&lt;br /&gt;
    this.add(p, &amp;quot;South&amp;quot;);&lt;br /&gt;
    // Create the buttons and arrange to handle button clicks&lt;br /&gt;
    Font font = new Font(&amp;quot;SansSerif&amp;quot;, Font.BOLD, 14);&lt;br /&gt;
    Button openfile = new Button(&amp;quot;Open File&amp;quot;);&lt;br /&gt;
    Button close = new Button(&amp;quot;Close&amp;quot;);&lt;br /&gt;
    openfile.addActionListener(this);&lt;br /&gt;
    openfile.setActionCommand(&amp;quot;open&amp;quot;);&lt;br /&gt;
    openfile.setFont(font);&lt;br /&gt;
    close.addActionListener(this);&lt;br /&gt;
    close.setActionCommand(&amp;quot;close&amp;quot;);&lt;br /&gt;
    close.setFont(font);&lt;br /&gt;
    p.add(openfile);&lt;br /&gt;
    p.add(close);&lt;br /&gt;
    this.pack();&lt;br /&gt;
    // Figure out the directory, from filename or current dir, if necessary&lt;br /&gt;
    if (directory == null) {&lt;br /&gt;
      File f;&lt;br /&gt;
      if ((filename != null) &amp;amp;&amp;amp; (f = new File(filename)).isAbsolute()) {&lt;br /&gt;
        directory = f.getParent();&lt;br /&gt;
        filename = f.getName();&lt;br /&gt;
      } else&lt;br /&gt;
        directory = System.getProperty(&amp;quot;user.dir&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    this.directory = directory; // Remember the directory, for FileDialog&lt;br /&gt;
    setFile(directory, filename); // Now load and display the file&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Load and display the specified file from the specified directory&lt;br /&gt;
   */&lt;br /&gt;
  public void setFile(String directory, String filename) {&lt;br /&gt;
    if ((filename == null) || (filename.length() == 0))&lt;br /&gt;
      return;&lt;br /&gt;
    File f;&lt;br /&gt;
    FileReader in = null;&lt;br /&gt;
    // Read and display the file contents. Since we&amp;quot;re reading text, we&lt;br /&gt;
    // use a FileReader instead of a FileInputStream.&lt;br /&gt;
    try {&lt;br /&gt;
      f = new File(directory, filename); // Create a file object&lt;br /&gt;
      in = new FileReader(f); // And a char stream to read it&lt;br /&gt;
      char[] buffer = new char[4096]; // Read 4K characters at a time&lt;br /&gt;
      int len; // How many chars read each time&lt;br /&gt;
      textarea.setText(&amp;quot;&amp;quot;); // Clear the text area&lt;br /&gt;
      while ((len = in.read(buffer)) != -1) { // Read a batch of chars&lt;br /&gt;
        String s = new String(buffer, 0, len); // Convert to a string&lt;br /&gt;
        textarea.append(s); // And display them&lt;br /&gt;
      }&lt;br /&gt;
      this.setTitle(&amp;quot;FileViewer: &amp;quot; + filename); // Set the window title&lt;br /&gt;
      textarea.setCaretPosition(0); // Go to start of file&lt;br /&gt;
    }&lt;br /&gt;
    // Display messages if something goes wrong&lt;br /&gt;
    catch (IOException e) {&lt;br /&gt;
      textarea.setText(e.getClass().getName() + &amp;quot;: &amp;quot; + e.getMessage());&lt;br /&gt;
      this.setTitle(&amp;quot;FileViewer: &amp;quot; + filename + &amp;quot;: I/O Exception&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    // Always be sure to close the input stream!&lt;br /&gt;
    finally {&lt;br /&gt;
      try {&lt;br /&gt;
        if (in != null)&lt;br /&gt;
          in.close();&lt;br /&gt;
      } catch (IOException e) {&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Handle button clicks&lt;br /&gt;
   */&lt;br /&gt;
  public void actionPerformed(ActionEvent e) {&lt;br /&gt;
    String cmd = e.getActionCommand();&lt;br /&gt;
    if (cmd.equals(&amp;quot;open&amp;quot;)) { // If user clicked &amp;quot;Open&amp;quot; button&lt;br /&gt;
      // Create a file dialog box to prompt for a new file to display&lt;br /&gt;
      FileDialog f = new FileDialog(this, &amp;quot;Open File&amp;quot;, FileDialog.LOAD);&lt;br /&gt;
      f.setDirectory(directory); // Set the default directory&lt;br /&gt;
      // Display the dialog and wait for the user&amp;quot;s response&lt;br /&gt;
      f.show();&lt;br /&gt;
      directory = f.getDirectory(); // Remember new default directory&lt;br /&gt;
      setFile(directory, f.getFile()); // Load and display selection&lt;br /&gt;
      f.dispose(); // Get rid of the dialog box&lt;br /&gt;
    } else if (cmd.equals(&amp;quot;close&amp;quot;)) // If user clicked &amp;quot;Close&amp;quot; button&lt;br /&gt;
      this.dispose(); // then close the window&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * The FileViewer can be used by other classes, or it can be used standalone&lt;br /&gt;
   * with this main() method.&lt;br /&gt;
   */&lt;br /&gt;
  static public void main(String[] args) throws IOException {&lt;br /&gt;
    // Create a FileViewer object&lt;br /&gt;
    Frame f = new FileViewer((args.length == 1) ? args[0] : null);&lt;br /&gt;
    // Arrange to exit when the FileViewer window closes&lt;br /&gt;
    f.addWindowListener(new WindowAdapter() {&lt;br /&gt;
      public void windowClosed(WindowEvent e) {&lt;br /&gt;
        System.exit(0);&lt;br /&gt;
      }&lt;br /&gt;
    });&lt;br /&gt;
    // And pop the window up&lt;br /&gt;
    f.show();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Use FileReader and FileWriter ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 1995 - 2008 Sun Microsystems, Inc.  All rights reserved.&lt;br /&gt;
 *&lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions&lt;br /&gt;
 * are met:&lt;br /&gt;
 *&lt;br /&gt;
 *   - Redistributions of source code must retain the above copyright&lt;br /&gt;
 *     notice, this list of conditions and the following disclaimer.&lt;br /&gt;
 *&lt;br /&gt;
 *   - Redistributions in binary form must reproduce the above copyright&lt;br /&gt;
 *     notice, this list of conditions and the following disclaimer in the&lt;br /&gt;
 *     documentation and/or other materials provided with the distribution.&lt;br /&gt;
 *&lt;br /&gt;
 *   - Neither the name of Sun Microsystems nor the names of its&lt;br /&gt;
 *     contributors may be used to endorse or promote products derived&lt;br /&gt;
 *     from this software without specific prior written permission.&lt;br /&gt;
 *&lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &amp;quot;AS&lt;br /&gt;
 * IS&amp;quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR&lt;br /&gt;
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR&lt;br /&gt;
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,&lt;br /&gt;
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR&lt;br /&gt;
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF&lt;br /&gt;
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING&lt;br /&gt;
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS&lt;br /&gt;
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 */&lt;br /&gt;
import java.io.File;&lt;br /&gt;
import java.io.FileReader;&lt;br /&gt;
import java.io.FileWriter;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
public class Copy {&lt;br /&gt;
  public static void main(String[] args) throws IOException {&lt;br /&gt;
    File inputFile = new File(&amp;quot;farrago.txt&amp;quot;);&lt;br /&gt;
    File outputFile = new File(&amp;quot;outagain.txt&amp;quot;);&lt;br /&gt;
    FileReader in = new FileReader(inputFile);&lt;br /&gt;
    FileWriter out = new FileWriter(outputFile);&lt;br /&gt;
    int c;&lt;br /&gt;
    while ((c = in.read()) != -1)&lt;br /&gt;
      out.write(c);&lt;br /&gt;
    in.close();&lt;br /&gt;
    out.close();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>