tags:

views:

37

answers:

1
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class CopyBytes1 {
    public static void main(String[] args) throws IOException {
        FileInputStream in = null;
        FileOutputStream out = null;
        try {
            in = new FileInputStream("c:\\aaa.txt");
            out = new FileOutputStream("c:\\outagain.txt");
            int c;

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

        } finally {
            if (in != null) {
                in.close();
            }
            if (out != null) {
                out.close();
            }
        }
    }
}

I have kept my aaa.txt in c: but while i compile its throwing FileNotFoundException. Why this is coming? Where should i keep my file?

+1  A: 

The exception is most likely from

in = new FileInputStream("c:\aaa.txt");

which you could verify if you posted the exception and showed line numbers.

make sure that your file isn't accidentally called aaa.txt.txt and is only showing aaa.txt in the windows explorer because you are hiding file extensions.

MeBigFatGuy
ya its from aaa.txt but its not showing anything like txt.txt. I checked it.
Sumithra
you checked it in windows explorer, or from the command line? use the command line.
MeBigFatGuy
now checked with command line its aaa.txt.txt how should i change it?
Sumithra
if you are programming, you should really turn the option on in windows to always show file extensions. Follow these instructions for doing so, and then edit the name in windows explorer: http://www.fileinfo.com/help/windows-show-extensions.html
MeBigFatGuy
Many thanks MeBigFatGuy!!! followed the step which u told now its working!!!
Sumithra
A good guess. +1
Adeel Ansari