Perry Smith

Java Questions & Answers

Home / Java Q & A Archive Page 4 / Java Q & A Archive / Java Main Page

java.io.FileNotFoundException
Wednesday, 17-Feb-99 17:04:19

153.37.9.186 writes:

I got this code straight off of java.sun.com's java tutorial on File IO under the JFC heading. I am running Java 1.2 and when I run the compiled application I get weird Exeption messages from the java console. I am assuming that I messed up in the way that I handled the file name with the FileDialog. Any help would be appreciated.

      ---------------
      import java.awt.*;
      import java.io.*;
      import java.util.zip.*;

      public class test extends Frame {
      public static void main(String[] args) { new test(); }

      public test() {
      super("test");
      this.setLayout(new FlowLayout());
      this.setSize(140, 60);
      this.show();
      }

      public Button button = new Button("Copy"); {
      add(button);
      }

      public Frame testFrame = new Frame();

      public void test() {
      FileDialog t = new FileDialog(testFrame, "Copy File:", FileDialog.LOAD);
      t.show();
      String testname = t.getFile();
      if (testname != null) {
      try {
      File inputFile = new File(testname);
      File outputFile = new File("Output");
      FileInputStream in = new FileInputStream(inputFile);
      FileOutputStream out = new FileOutputStream(outputFile);
      int c;
      while ((c = in.read()) != -1)
      out.write(c);
      in.close();
      out.close();
      }
      catch (IOException e) { System.out.println(e); }
      }
      }

      public boolean action(Event e, Object arg) {
      if (e.target == button) {
      test();
      return true;
      }
      else return false;
      }
      }
      ---------------

      Rory


Response
Re: java.io.FileNotFoundException
Wednesday, 17-Feb-99 18:14:37

24.1.16.214 writes:

you wrote:

      FileDialog t = new FileDialog(testFrame, "Copy File:", FileDialog.LOAD);
             t.show();
             String testname = t.getFile();




      for the line that assigns the testname String,
      try this:

             String testname = t.getDirectory() + t.getFile();



      -calyxa

Home / Java Q & A Archive Page 4 / Java Q & A Archive / Java Main Page