开发者

File IO doubt in the following code

开发者 https://www.devze.com 2023-01-22 12:56 出处:网络
import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class CopyBytes1 {
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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消