• Post Reply Bookmark Topic Watch Topic
  • New Topic

error in reading from a file

 
Ahmad Aldarrak
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I'm getting this error:

java.io.FileNotFoundException: shapes.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileReader.<init>(FileReader.java:55)
at folder.Folder.Test.main(Test.java:19)
Exception in thread "main"


And this is my code (not long):

package folder.Folder;
import java.io.*;
public class Test{

public static void main(String[] args) throws IOException {

File inputFile = new File("shapes.txt");
File outputFile = new File("copy.txt");

FileReader in = new FileReader(inputFile);
FileWriter out = new FileWriter(outputFile);
int c;

while ((c = in.read()) != -1)
out.write(c);

in.close();
out.close();
}
}


I'm just copying from shapes.txt to copy.txt

and yes, the file is in the same directory.

I'm using NetBeans IDE 3.6

Thank you
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like the input is not found. Before you try to read, display the path of the input File object. (file.getPath()) It's likely reading from a directory that is not the one you expect. You might want to give a fully qualified path to the input and output files.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!