Hoi,
Vraagje: Hoe kan ik input van een user opslaan in mijn progje en weer terugprinten?
Ik weet dat ik System.in.read() moet gebruiken, maar kom er maar niet achter HOE. Op de site van SUN staat:
Kan iemand me een tip geven? Ik ben zo ver dat ik wel code in kan tikken, maar dat zijn bytes ipv chars, dus krijg ik rotzooi als output.
Vraagje: Hoe kan ik input van een user opslaan in mijn progje en weer terugprinten?
Ik weet dat ik System.in.read() moet gebruiken, maar kom er maar niet achter HOE. Op de site van SUN staat:
AARG!Standard Input Stream
The System class provides a stream for reading text--the standard input stream.
[PENDING: put in an example and more description or a pointer or something]
Standard Output and Error Streams
Kan iemand me een tip geven? Ik ben zo ver dat ik wel code in kan tikken, maar dat zijn bytes ipv chars, dus krijg ik rotzooi als output.
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
| package cmdline;
import java.io.*;
public class Cmdline
{
public Cmdline()
{
//Creating the default input char
System.out.print(">");
//asking for input
byte[] bytebuf = new byte[100];
try
{
System.in.read(bytebuf,0,100);
}
catch(IOException e)
{
System.out.println("ERROR");
}
//Print the input back to user (echo)
System.out.println(bytebuf);
}
public static void main(String[] args)
{
Cmdline cmdline1 = new Cmdline();
return;
}
} |