Article View: aus.computers.java
Article #656Re: Simple Java Input Help.
From: glennL
Date: Sat, 01 Jul 2000 00:00
Date: Sat, 01 Jul 2000 00:00
54 lines
1747 bytes
1747 bytes
Hi Myke,
Try this.
/**
* Read a string from the console, terminating input with a newline.
* @return The input string (null if exception).
*/
public static String readString() {
int ch = 0;
String r = "";
boolean done = false;
while (!done) {
try {
ch = System.in.read();
if (ch < 0 || (char)ch == '\n')
done = true;
else if ( (char) ch != '\r') // ignore cr
r = r + (char) ch;
}
catch(java.io.IOException e) {
done = true;
return null;
}
}
return r;
}
Cheers,
Glenn.
Myke <myke@net2000.com.au> wrote in message
news:VGA55.50$7f7.4121@nsw.nnrp.telstra.net...
> I thought it would be easy. I can do it with any other language I have
had
> to use.
>
> All I want to do is ask a user for text input at the command line.
>
> Is this possible?
>
> I have found methods to read files, read test input from input boxes etc,
> but I want it in a text based interface so I do not have to worry to much
> about applet programming. (I am just begining)
>
> Any help would be greatly appreciated.
>
> Thanks
> Myke
>
>
Technical Details
Message-ID:
<8p7kj8.55t.ln@garfield.glass>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<VGA55.50$7f7.4121@nsw.nnrp.telstra.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d6db,20edaadabe63645e X-Google-Attributes: gid10d6db,public From: "glennL" <glenn@email.nu> Subject: Re: Simple Java Input Help. Date: 2000/07/01 Message-ID: <8p7kj8.55t.ln@garfield.glass> X-Deja-AN: 641390358 References: <VGA55.50$7f7.4121@nsw.nnrp.telstra.net> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 Organization: Melbourne PC User Group Inc, Australia X-MSMail-Priority: Normal Newsgroups: aus.computers.java