
1.Create a class called ReadFromFile. Create a file object and use the file object to create an input stream object to read the file â??employee.txtâ?? (use byte stream classes).If the file does not exists an exception should be thrown. An error message along with the path of the file(use the getAbsolutePath() method) should be displayed.

import java.io.*;
class InputStreamAndOutputStream
{
public static void main(String[] args)throws Exception{
File f=new File("C:/Hello.txt");
if(f.exists()){
InputStream in = new FileInputStream(f);
OutputStream out = System.out;
int nextChar;
while ( ( nextChar = in.read() ) != -1 )
out.write((char) nextChar );
out.write('\n' );
out.flush();
}
else{
System.out.println(f.getAbsolutePath()+" does not exist");
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.