Results 1 to 2 of 2

Thread: FileHandling

  1. #1
    er1c550n20 is offline Member
    Join Date
    Mar 2010
    Posts
    9
    Rep Power
    0

    Default FileHandling

    thnx JosAH for you earlier help...
    I've got this new prob thnx in advance..
    java.io.FileNotFoundException: input.dat (The system cannot find the file specified)
    given below is code

    import java.io.*;
    class CopyCharacters
    {
    public static void main (String args[])
    {
    File inFile = new File ("input.dat");
    File outFile = new File ("output.dat");
    FileReader ins = null;
    FileWriter outs = null;
    try
    {
    ins = new FileReader (inFile);
    outs = new FileWriter (outFile);
    int ch;
    while((ch=ins.read())!=-1)
    {
    outs.write (ch);
    }
    }
    catch (IOException e)
    {
    System.out.println(e);
    System.exit(-1);
    }
    finally
    {
    try
    {
    ins.close();
    outs.close();
    }
    catch (IOException e) {}
    }
    }
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,524
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by er1c550n20 View Post
    thnx JosAH for you earlier help...
    I've got this new prob thnx in advance..
    java.io.FileNotFoundException: input.dat (The system cannot find the file specified)
    Do the following checks:

    Java Code:
    File inFile= new File("input.dat");
    System.out.println(inFile.getAbsolutePath());
    System.out.println("exists: "+inFile.exists());
    See if that File objects points to the file you had in mind. Probably it doesn't.

    kind regards,

    Jos

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •