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:ChatClient.java

  public static void main(String[] args) throws Exception {
  DatagramSocket s = new DatagramSocket();
  byte[] buf = new byte[1000];
  DatagramPacket dp = new DatagramPacket(buf, buf.length);

  InetAddress hostAddress = InetAddress.getByName("localhost");
  while (true) {/*from  w  ww .  j a  v  a  2s .  c om*/
    BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
    String outMessage = stdin.readLine();

    if (outMessage.equals("bye"))
      break;
    String outString = "Client say: " + outMessage;
    buf = outString.getBytes();

    DatagramPacket out = new DatagramPacket(buf, buf.length, hostAddress, 9999);
    s.send(out);

    s.receive(dp);
    String rcvd = "rcvd from " + dp.getAddress() + ", " + dp.getPort() + ": "
        + new String(dp.getData(), 0, dp.getLength());
    System.out.println(rcvd);
  }
}

From source file:Main.java

public static void main(String[] args) {
    char[][] original = new char[3][3];
    Scanner s = new Scanner(System.in);
    System.out.println("Enter values: ");
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            original[i][j] = s.next().charAt(0);
        }/*from www .j ava2  s  .c  o m*/
    }
    rotate(original);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    System.out.println("Count number of rows in a specific table!");
    Connection con = null;//from   w  ww  .  ja  va  2 s. c o  m
    int count = 0;
    Class.forName("com.mysql.jdbc.Driver");
    con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial", "root", "root");

    Statement st = con.createStatement();
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    ResultSet res = st.executeQuery("SELECT COUNT(*) FROM EMP");
    while (res.next()) {
        count = res.getInt(1);
    }
    System.out.println("Number of row:" + count);
}

From source file:ResultSetMetaDataExample.java

public static void main(String args[]) throws Exception {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:Inventory", "", "");
    Statement stmt = con.createStatement();

    boolean notDone = true;
    String sqlStr = null;//from  w  w  w  .  j  av  a  2 s  .c o  m
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    while (notDone) {
        sqlStr = br.readLine();
        if (sqlStr.startsWith("SELECT") || sqlStr.startsWith("select")) {
            ResultSet rs = stmt.executeQuery(sqlStr);
            ResultSetMetaData rsmd = rs.getMetaData();
            int columnCount = rsmd.getColumnCount();
            for (int x = 1; x <= columnCount; x++) {
                String columnName = rsmd.getColumnName(x);
                System.out.print(columnName);
            }
            while (rs.next()) {
                for (int x = 1; x <= columnCount; x++) {
                    if (rsmd.getColumnTypeName(x).compareTo("CURRENCY") == 0)
                        System.out.print("$");
                    String resultStr = rs.getString(x);
                    System.out.print(resultStr + "\t");
                }
            }
        } else if (sqlStr.startsWith("exit"))
            notDone = false;
    }
    stmt.close();
    con.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Socket socket = new Socket("localhost", 12900);
    System.out.println("Started client  socket at " + socket.getLocalSocketAddress());
    BufferedReader socketReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    BufferedWriter socketWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
    BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in));

    String promptMsg = "Please enter a  message  (Bye  to quit):";
    String outMsg = null;/*from   w w w.ja v  a 2 s . com*/

    System.out.print(promptMsg);
    while ((outMsg = consoleReader.readLine()) != null) {
        if (outMsg.equalsIgnoreCase("bye")) {
            break;
        }
        // Add a new line to the message to the server,
        // because the server reads one line at a time.
        socketWriter.write(outMsg);
        socketWriter.write("\n");
        socketWriter.flush();

        // Read and display the message from the server
        String inMsg = socketReader.readLine();
        System.out.println("Server: " + inMsg);
        System.out.println(); // Print a blank line
        System.out.print(promptMsg);
    }
    socket.close();
}

From source file:Test.java

  public static void main(String[] args) throws Exception {

  SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory
      .getDefault();/*from  www  .  j a v  a2  s .c o  m*/
  SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(
      "localhost", 9999);

  InputStreamReader inputStreamReader = new InputStreamReader(System.in);
  BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

  OutputStream outputStream = sslSocket.getOutputStream();
  OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
  BufferedWriter bufferedwriter = new BufferedWriter(outputStreamWriter);

  String line = null;
  while ((line = bufferedReader.readLine()) != null) {
    bufferedwriter.write(line + '\n');
    bufferedwriter.flush();
  }
}

From source file:Lab2.java

/**
 * @param args the command line arguments
 *///from w  w  w  .j  a  v a 2 s.c o  m
public static void main(String[] args) {
    Preprocessor p = new Preprocessor();
    p.parse();
    Query q;
    boolean cont = true;
    Scanner input = new Scanner(System.in);
    String yesOrNo;
    String oOrC;
    ArrayList<Document> scores;

    System.out.println("Would you like to use cosine similarity or okapi to score queries? (C/O)");
    oOrC = input.nextLine();
    while (cont) {
        System.out.println("Enter a query: ");
        /**
         * We don't need the query class, we can just stem it and stopword it then make a document out of it.
         */
        q = new Query(input.nextLine());

        if (oOrC.equals("O") || oOrC.equals("o")) {
            scores = p.calcQueryOkapiScore(q);
        } else {
            scores = p.calcQueryCosineSimilarity(q);
        }

        System.out.println("Documents returned from cosine similarity analysis on query are: ");
        for (Document doc : scores) {
            System.out.println("Text :" + doc.origUtterance);
        }

        System.out.println("Would you like to enter another? Y/N");
        yesOrNo = input.nextLine();
        if (yesOrNo.equals("N") || yesOrNo.equals("n")) {
            cont = false;
        }
    }
}

From source file:it.pcan.test.integration.amqp.MainServer.java

/**
 * @param args the command line arguments
 * @throws java.lang.Exception/*from ww w.  j a  v  a 2  s .co  m*/
 */
public static void main(String[] args) throws Exception {
    try (ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:/config/serverApplicationContext.xml")) {
        new Scanner(System.in).nextLine(); // Press Enter key to stop
        System.out.println("Done.");
    }
}

From source file:MainClass.java

public static void main(String[] args) throws IOException {
    PrintStream console = System.out;
    BufferedInputStream in = new BufferedInputStream(new FileInputStream("Redirecting.java"));
    PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream("test.out")));
    System.setIn(in);//from   w  w w . j  a v a 2s . c o  m
    System.setOut(out);
    System.setErr(out);
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String s;
    while ((s = br.readLine()) != null)
        System.out.println(s);
    out.close();
    System.setOut(console);
}

From source file:Test.java

public static void main(String[] args) throws Exception {

    AsynchronousSocketChannel client = AsynchronousSocketChannel.open();
    InetSocketAddress address = new InetSocketAddress("localhost", 5000);

    Future<Void> future = client.connect(address);
    System.out.println("Client: Waiting for the connection to complete");
    future.get();/*from  www.ja va  2  s.c  om*/

    String message = "";
    while (!message.equals("quit")) {
        System.out.print("Enter a message: ");
        Scanner scanner = new Scanner(System.in);
        message = scanner.nextLine();
        System.out.println("Client: Sending ...");
        ByteBuffer buffer = ByteBuffer.wrap(message.getBytes());
        System.out.println("Client: Message sent: " + new String(buffer.array()));
        client.write(buffer);
    }
}