Hi everybody,
My program reads user commands from the console until it finds an EOF. My question is: how does the program knows that an EOF has been inserted? And how does a user introduces an EOF as input through the console?
I´m using the method below to read the input:
static String readLn (int maxLg)
{
byte lin[] = new byte[maxLg];
int lg = 0, car = -1;
String line = "";
try
{
while (lg < maxLg)
{
car = System.in.read ();
if ((car < 0) || (car == '\n'))
break;
lin[lg++] += car;
}
}
catch (IOException e)
{
return (null);
}
if ((car < 0) && (lg == 0)){
return (null); // eof
}
return (new String (lin, 0, lg));
}
Thus, to read the input the program calls that method, readLn(). For example:
String input = readLn(1024).tr im();. From this example how do i know that the string "input" is an EOF? I´d be much thankful for any help.
Best Regards
My program reads user commands from the console until it finds an EOF. My question is: how does the program knows that an EOF has been inserted? And how does a user introduces an EOF as input through the console?
I´m using the method below to read the input:
static String readLn (int maxLg)
{
byte lin[] = new byte[maxLg];
int lg = 0, car = -1;
String line = "";
try
{
while (lg < maxLg)
{
car = System.in.read ();
if ((car < 0) || (car == '\n'))
break;
lin[lg++] += car;
}
}
catch (IOException e)
{
return (null);
}
if ((car < 0) && (lg == 0)){
return (null); // eof
}
return (new String (lin, 0, lg));
}
Thus, to read the input the program calls that method, readLn(). For example:
String input = readLn(1024).tr im();. From this example how do i know that the string "input" is an EOF? I´d be much thankful for any help.
Best Regards
Comment