0

I am trying to read the data in the file using FileInputStream and FileOutputStream.But,I am getting an Exception saying File.io.FileNotFoundException.

I have saved the file abc.txt in the same Folder where my class IoConcepts is

Can Anyone guide me what I am doing wrong?

package io;

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

public class IoConcepts 
{

public static void main(String[] args) throws FileNotFoundException,IOException
{
    FileInputStream fis=new FileInputStream("abc.txt");
    FileOutputStream fos=new FileOutputStream("abcd.txt");
    int c;
    while((c=fis.read())!=-1)
    {System.out.println(c);
        fos.write(c);
    }

}

}

Exception:

Exception in thread "main" java.io.FileNotFoundException: abc.txt (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:93)
at io.IoConcepts.main(IoConcepts.java:13)
Jason arora
  • 550
  • 3
  • 8
  • 22
  • 1
    Maybe because there is no `abc.txt` file located **in the location where you're looking**. Do you understand the Java concept about the user's home directory? – Hovercraft Full Of Eels Apr 16 '16 at 02:38
  • @HovercraftFullOfEels Home Directory.I have saved the abc.txt file where my IOConcepts.java file is i.e in src folder--IoPackage--and 2 file one is IoConcept.java and another is abc.txt – Jason arora Apr 16 '16 at 02:45
  • Which means that you don't yet understand the concept and are looking in the wrong place for the file. Please read the link to the duplicate question. – Hovercraft Full Of Eels Apr 16 '16 at 02:47
  • As a side concern: you shouldn't use naked file streams to read and write text files, since with these you'll get gibberish. You'll want to wrap them in readers and writers. – Hovercraft Full Of Eels Apr 16 '16 at 02:49
  • @HovercraftFullOfEels Sir I know this is my first Example.But Please can you tell directly tell what I am doing wrong and how to correct it. – Jason arora Apr 16 '16 at 02:50

0 Answers0