Example usage for java.lang System in

List of usage examples for java.lang System in

Introduction

In this page you can find the example usage for java.lang System in.

Prototype

InputStream in

To view the source code for java.lang System in.

Click Source Link

Document

The "standard" input stream.

Usage

From source file:MainClass.java

public static void main(String[] av) throws IOException {
    StreamTokenizer tf = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    String s = null;//from   w  w  w  . j a v  a2  s.  c om
    int i;

    while ((i = tf.nextToken()) != StreamTokenizer.TT_EOF) {
        switch (i) {
        case StreamTokenizer.TT_EOF:
            System.out.println("End of file");
            break;
        case StreamTokenizer.TT_EOL:
            System.out.println("End of line");
            break;
        case StreamTokenizer.TT_NUMBER:
            System.out.println("Number " + tf.nval);
            break;
        case StreamTokenizer.TT_WORD:
            System.out.println("Word, length " + tf.sval.length() + "->" + tf.sval);
            break;
        default:
            System.out.println("What is it? i = " + i);
        }
    }

}

From source file:MainClass.java

public static void main(String[] args) {
    try {/*from   w w w.  ja  v  a2s.c  o  m*/
        URL url = new URL("file:youraudiofile.wav");
        AudioClip ac = Applet.newAudioClip(url);
        ac.play();

        System.out.println("Press any key to exit.");
        System.in.read();
        ac.stop();
    } catch (Exception e) {
        System.out.println(e);
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
    System.out.println(stdin.readLine());
    BufferedReader in = new BufferedReader(new FileReader("Main.java"));
    String s, s2 = new String();
    while ((s = in.readLine()) != null)
        s2 += s + "\n";
    in.close();//  w ww.j a va  2 s  .c  o  m
    StringReader in1 = new StringReader(s2);
    int c;
    while ((c = in1.read()) != -1)
        System.out.print((char) c);
    BufferedReader in2 = new BufferedReader(new StringReader(s2));
    PrintWriter out1 = new PrintWriter(new BufferedWriter(new FileWriter("IODemo.out")));
    int lineCount = 1;
    while ((s = in2.readLine()) != null)
        out1.println(lineCount++ + ": " + s);
    out1.close();
}

From source file:Grep.java

public static void main(String args[]) throws Exception {
    String regex = "";
    InputStream in = System.in;

    regex = args[0];//from  w  w  w.  j a  v a  2  s. com
    in = new BufferedInputStream(new FileInputStream(args[1]));
    Pattern p = null;

    p = Pattern.compile(regex);

    BufferedReader buff = new BufferedReader(new InputStreamReader(in));

    String a;
    for (a = buff.readLine(); a != null; a = buff.readLine()) {
        Matcher m = p.matcher(a);
        if (m.find()) {
            System.out.println(a);
        }
    }
}

From source file:Main.java

public static void main(String[] args) {
    System.out.println("Enter a number.");
    double numberFromConsole;
    try {// w w  w  . ja  va  2 s.com
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        String s = br.readLine();
        DecimalFormat df = new DecimalFormat();
        Number n = df.parse(s);
        numberFromConsole = n.doubleValue();
    } catch (IOException e) {
        numberFromConsole = 0;
    } catch (ParseException e) {
        numberFromConsole = 0;
    }
    System.out.println(numberFromConsole);
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    InetAddress server = InetAddress.getByName("localhost");
    BufferedReader userInput = new BufferedReader(new InputStreamReader(System.in));
    DatagramSocket theSocket = new DatagramSocket();
    while (true) {
        String theLine = userInput.readLine();
        if (theLine.equals("."))
            break;
        byte[] data = theLine.getBytes();
        DatagramPacket theOutput = new DatagramPacket(data, data.length, server, 99999);
        theSocket.send(theOutput);/*w  ww  . j a  v  a2s  .  c  o m*/
    }

}

From source file:Main.java

public static void main(String[] args) throws IOException {
    ExecutorService service = Executors.newFixedThreadPool(4);
    BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
    String line;//from   w w  w  .j av a 2s .c o  m
    while ((line = buffer.readLine()) != null) {
        service.execute(new Worker(line));
    }
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    ByteArrayOutputStream f = new ByteArrayOutputStream(12);
    System.out.println("Please 10 characters and a return");
    while (f.size() != 10) {
        f.write(System.in.read());
    }/*from w  w w. j a  va2  s  . c om*/
    System.out.println("Buffer as a string");
    System.out.println(f.toString());
    System.out.println("Into array");
    byte b[] = f.toByteArray();
    for (int i = 0; i < b.length; i++) {
        System.out.print((char) b[i]);
    }
    System.out.println();
    OutputStream f2 = new FileOutputStream("test.txt");
    f.writeTo(f2);
    f.reset();
    System.out.println("10 characters and a return");
    while (f.size() != 10) {
        f.write(System.in.read());
    }
    System.out.println("Done..");
}

From source file:Vis.java

public static void main(String[] av) {
    Vis v = new Vis();
    if (av.length == 0)
        v.process(new BufferedReader(new InputStreamReader(System.in)));
    else//w  w w.  j a  v a 2  s. c  o  m
        for (int i = 0; i < av.length; i++)
            try {
                v.process(new BufferedReader(new FileReader(av[i])));
            } catch (FileNotFoundException e) {
                System.err.println(e);
            }
}

From source file:WriteServer.java

public static void main(String args[]) throws Exception {
    int serverPort = 998;

    int buffer_size = 1024;

    byte buffer[] = new byte[buffer_size];

    DatagramSocket ds = new DatagramSocket(serverPort);
    int pos = 0;/*  ww w .  j a v  a  2  s. c  o  m*/
    while (true) {
        int c = System.in.read();
        switch (c) {
        case -1:
            System.out.println("Server Quits.");
            return;
        case '\r':
            break;
        case '\n':
            ds.send(new DatagramPacket(buffer, pos, InetAddress.getLocalHost(), 999));
            pos = 0;
            break;
        default:
            buffer[pos++] = (byte) c;
        }
    }

}