JAVA: system.in.read()

Pagina: 1
Acties:

  • Carnifex
  • Registratie: Januari 2000
  • Laatst online: 18-09 06:59
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:
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
AARG! :(

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;
  }
}

  • wasigh
  • Registratie: Januari 2001
  • Niet online

wasigh

wasigh.blogspot.com

gebruik anders een BufferedInputReader dan kun je de input per regel lezen (zie api-doc)