
how to read input to a file from console

Hi Friend,
Try the following code:
import java.io.*;
import java.util.*;
public class ReadFile{
public static void main(String[] args) throws IOException{
Scanner input=new Scanner(System.in);
System.out.println("Enter File Name with path: ");
String st=input.next();
File f=new File(st);
if(!f.exists()&& f.length()<0)
System.out.println("The specified file does not exist");
else{
FileInputStream finp=new FileInputStream(f);
byte b;
do{
b=(byte)finp.read();
System.out.print((char)b);
}
while(b!=-1);
finp.close();
}
}
}
Thanks
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.