I am calling the name_setter() method from the 'main' by creating an object of customer class to get the input from console and store the name entered in the 'name' variable of the object of the customer class.
import java.io.*;
public class Rental {
public static void main(String[] args) {
customer c = new customer();
c.name_setter(); // calls the method from customer class
}
}
class customer {
String name;
String name_setter() {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
System.out.println("Enter the name:"); // executes till here
name = br.readLine(); // stream close error
System.out.println(name);
if (name.length() == 0) {
name = br.readLine();
}
} catch (IOException e) {
System.out.println("" + e);
}
return name;
}
}
the error i am getting is:
java.io.IOException: Stream closed