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:cit360.sandbox.CIT360SandBox.java

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

    Scanner input = new Scanner(System.in);
    System.out.println("What is your name?");
    CIT360SandBox.firstName = input.next();

    System.out.println("Welcome " + firstName + "!");

    CIT360SandBox.App.mainMenu();// ww  w.  j a va  2  s .co  m

}

From source file:listfiles.ListFiles.java

/**
 * @param args the command line arguments
 *//*from  www  . j av  a 2s .c o m*/
public static void main(String[] args) {
    // TODO code application logic here
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String folderPath = "";
    String fileName = "DirectoryFiles.xlsx";

    try {
        System.out.println("Folder path :");
        folderPath = reader.readLine();
        //System.out.println("Output File Name :");
        //fileName = reader.readLine();

        XSSFWorkbook wb = new XSSFWorkbook();
        FileOutputStream fileOut = new FileOutputStream(folderPath + "\\" + fileName);
        XSSFSheet sheet1 = wb.createSheet("Files");
        int row = 0;
        Stream<Path> stream = Files.walk(Paths.get(folderPath));
        Iterator<Path> pathIt = stream.iterator();
        String ext = "";

        while (pathIt.hasNext()) {
            Path filePath = pathIt.next();
            Cell cell1 = checkRowCellExists(sheet1, row, 0);
            Cell cell2 = checkRowCellExists(sheet1, row, 1);
            row++;
            ext = FilenameUtils.getExtension(filePath.getFileName().toString());
            cell1.setCellValue(filePath.getFileName().toString());
            cell2.setCellValue(ext);

        }
        sheet1.autoSizeColumn(0);
        sheet1.autoSizeColumn(1);

        wb.write(fileOut);
        fileOut.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    System.out.println("Program Finished");
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault();

    String hostName = "hostName";
    String fileName = "fileName";

    SSLSocket sslsock = (SSLSocket) factory.createSocket(hostName, 443);

    SSLSession session = sslsock.getSession();
    X509Certificate cert;/*from  w ww.j av a 2s.  co  m*/
    try {
        cert = (X509Certificate) session.getPeerCertificates()[0];
    } catch (SSLPeerUnverifiedException e) {
        System.err.println(session.getPeerHost() + " did not present a valid certificate.");
        return;
    }

    System.out.println(session.getPeerHost() + " has presented a certificate belonging to:");
    Principal p = cert.getSubjectDN();
    System.out.println("\t[" + p.getName() + "]");
    System.out.println("The certificate bears the valid signature of:");
    System.out.println("\t[" + cert.getIssuerDN().getName() + "]");

    System.out.print("Do you trust this certificate (y/n)? ");
    System.out.flush();
    BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
    if (Character.toLowerCase(console.readLine().charAt(0)) != 'y')
        return;

    PrintWriter out = new PrintWriter(sslsock.getOutputStream());

    out.print("GET " + fileName + " HTTP/1.0\r\n\r\n");
    out.flush();

    BufferedReader in = new BufferedReader(new InputStreamReader(sslsock.getInputStream()));
    String line;
    while ((line = in.readLine()) != null)
        System.out.println(line);

    sslsock.close();
}

From source file:com.alibaba.dubbo.examples.callback.CallbackConsumer.java

public static void main(String[] args) throws Exception {
    String config = CallbackConsumer.class.getPackage().getName().replace('.', '/') + "/callback-consumer.xml";
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
    context.start();/*from www .  j  a  v  a2s.co m*/
    CallbackService callbackService = (CallbackService) context.getBean("callbackService");
    callbackService.addListener("foo.bar", new CallbackListener() {
        public void changed(String msg) {
            System.out.println("callback1:" + msg);
        }
    });
    System.in.read();
}

From source file:bankconsoleapp.console.Main.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) {

    //Injecting applicationContext to main
    ApplicationContext context = new ClassPathXmlApplicationContext("bankconsoleapp/applicationContext.xml");

    EmployeeService eS = context.getBean("EmployeeService", EmployeeService.class);
    CustomerService cS = context.getBean("CustomerService", CustomerService.class);
    SavingService sS = context.getBean("SavingService", SavingService.class);

    String userName, pass;
    Scanner in = new Scanner(System.in);
    boolean user = false;
    boolean savingRedo = false;

    do {

        System.out.println("Enter Employee ID:");
        userName = in.nextLine();
        for (Employee emp : eS.getAllEmp()) {
            if (userName.equals(emp.geteID())) {
                System.out.println("Password:");
                pass = in.nextLine();
                for (Employee em : eS.getAllEmp()) {
                    if (pass.equals(em.getPassword())) {

                        user = true;
                    }
                }
            }
        }

    } while (!user);

    long start = System.currentTimeMillis();
    long end = start + 60 * 1000; // 60 seconds * 1000 ms/sec
    int operation = 0;
    int userChoice;

    boolean quit = false;
    do {
        System.out.println("ACME Bank Saving System:");
        System.out.println("------------------------");
        System.out.println("1. Create Customer & Saving Account");
        System.out.println("2. Deposit Money");
        System.out.println("3. Withdraw Money");
        System.out.println("4. View Balance");
        System.out.println("5. Quit");
        System.out.print("Operation count: " + operation + "(Shut down at 5)");
        userChoice = in.nextInt();
        switch (userChoice) {
        case 1:

            //create customer, then saving account regard to existing customer( maximum 2 SA per Customer)
            System.out.println("Create Customer :");
            String FirstN, LastN, DoB, accNum, answer;

            Scanner sc = new Scanner(System.in);
            Customer c = new Customer();
            int saID = 0;

            System.out.println("Enter First Name:");
            FirstN = sc.nextLine();
            c.setFname(FirstN);
            System.out.println("Enter Last Name:");
            LastN = sc.nextLine();
            c.setLname(LastN);
            System.out.println("Enter Date of Birth:");
            DoB = sc.nextLine();
            c.setDoB(DoB);

            do {

                System.out.println("Creating saving acount, Enter Account Number:");
                accNum = sc.nextLine();
                c.setSA(accNum);
                c.setSavingAccounts(c.getSA());
                saID++;
                System.out.println("Create another SA? Y/N?");
                answer = sc.nextLine();
                if (answer.equals("n")) {
                    savingRedo = true;
                }
                if (saID == 2) {
                    System.out.println("Maximum Saving account reached!");
                }
            } while (!savingRedo && saID != 2);

            cS.createCustomer(c);
            operation++;

            break;
        case 2:
            // deposit

            String acNum;
            int amt;
            Scanner sc1 = new Scanner(System.in);
            System.out.println("Enter Saving Account number u wish to do deposit.");
            acNum = sc1.nextLine();
            System.out.println("Enter amount :");
            amt = sc1.nextInt();

            sS.deposit(acNum, amt);
            operation++;

            break;
        case 3:
            String acNums;
            int amts;
            Scanner sc2 = new Scanner(System.in);
            System.out.println("Enter Saving Account number u wish to do withdraw.");
            acNums = sc2.nextLine();
            System.out.println("Enter amount :");
            amts = sc2.nextInt();

            sS.withdraw(acNums, amts);
            operation++;
            break;

        case 4:
            // view
            System.out.println("Saving Account Balance:");
            System.out.println(sS.getAllSA());
            operation++;
            break;

        case 5:
            quit = true;
            break;
        default:
            System.out.println("Wrong choice.");
            break;
        }
        System.out.println();
        if (operation == 5) {
            System.out.println("5 operation reached, System shutdown.");
        }
        if (System.currentTimeMillis() > end) {
            System.out.println("Session Expired.");
        }
    } while (!quit && operation != 5 && System.currentTimeMillis() < end);
    System.out.println("Bye!");

}

From source file:$.StartServer.java

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

        initSpringContainer();//from www  .ja v  a 2  s  . co  m

        context.start();

        System.out.println("you can close spring container by input shutdown command");

        while (true) {
            scanner = new Scanner(System.in);
            if ("shutdown".equalsIgnoreCase(scanner.next())) {
                scanner.close();
                break;
            }
        }

        closeSpringContainer();
    }

From source file:StackTraceTest.java

public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    System.out.print("Enter n: ");
    int n = in.nextInt();
    factorial(n);//from   ww w  .  j  a  v  a2s .  c o  m
}

From source file:ee.ria.xroad.common.conf.globalconfextension.StdinValidator.java

/**
 * Program entry point//from ww w  .ja  v  a2  s .  c  om
 */
public static void main(String[] args) throws Exception {
    String string = IOUtils.toString(System.in, StandardCharsets.UTF_8.toString());
    System.out.println(string);
    OcspNextUpdateSchemaValidator.validate(string);
}

From source file:driver.ieSystem2.java

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

    Scanner sc = new Scanner(System.in);
    boolean login = false;
    int check = 0;
    int id = 0;//from www. j  a v  a  2  s.c  om
    String user = "";
    String pass = "";
    Person person = null;
    Date day = null;

    JOptionPane.showMessageDialog(null, "WELCOME TO SYSTEM", "Starting Project",
            JOptionPane.INFORMATION_MESSAGE);
    do {
        System.out.println("What do you want?");
        System.out.println("press 1 : Login");
        System.out.println("press 2 : Create New User");
        System.out.println("Press 3 : Exit ");
        System.out.println("");
        do {
            try {
                System.out.print("Enter: ");
                check = sc.nextInt();
            } catch (InputMismatchException e) {
                JOptionPane.showMessageDialog(null, "Invalid Input", "Message", JOptionPane.WARNING_MESSAGE);
                sc.next();
            }
        } while (check <= 1 && check >= 3);

        // EXIT 
        if (check == 3) {
            System.out.println("Close Application");
            System.exit(0);
        }
        // CREATE USER
        if (check == 2) {
            System.out.println("-----------------------------------------");
            System.out.println("Create New User");
            System.out.println("-----------------------------------------");
            System.out.print("Account ID: ");
            id = sc.nextInt();
            System.out.print("Username: ");
            user = sc.next();
            System.out.print("Password: ");
            pass = sc.next();
            try {
                Person.createUser(id, user, pass, 0, 0, 0, 0, 0);
                System.out.println("-----------------------------------------");
                System.out.println("Create Complete");
                System.out.println("-----------------------------------------");
            } catch (Exception e) {
                System.out.println("-----------------------------------------");
                System.out.println("Error, Try again");
                System.out.println("-----------------------------------------");
            }
        } else if (check == 1) {
            // LOGIN
            do {
                System.out.println("-----------------------------------------");
                System.out.println("LOGIN ");
                System.out.print("Username: ");
                user = sc.next();
                System.out.print("Password: ");
                pass = sc.next();
                if (Person.checkUser(user, pass)) {
                    System.out.println("-----------------------------------------");
                    System.out.println("Login Complete");
                } else {
                    System.out.println("-----------------------------------------");
                    System.out.println("Invalid Username / Password");
                }
            } while (!Person.checkUser(user, pass));
        }
    } while (check != 1);
    login = true;

    person = new Person(user);
    do {
        System.out.println("-----------------------------------------");
        System.out.println("Hi " + person.getPerName());
        System.out.println("Press 1 : Add Income");
        System.out.println("Press 2 : Add Expense");
        System.out.println("Press 3 : Add Save");
        System.out.println("Press 4 : History");
        System.out.println("Press 5 : Search");
        System.out.println("Press 6 : Analytics");
        System.out.println("Press 7 : Total");
        System.out.println("Press 8 : All Summary");
        System.out.println("Press 9 : Sign Out");
        do {
            try {
                System.out.print("Enter : ");
                check = sc.nextInt();
            } catch (InputMismatchException e) {
                System.out.println("Invalid Input");
                sc.next();
            }
        } while (check <= 1 && check >= 5);
        // Add Income
        if (check == 1) {
            double Income;
            String catalog = "";
            double IncomeTotal = 0;
            catalog = JOptionPane.showInputDialog("What is your income : ");
            Income = Integer.parseInt(JOptionPane.showInputDialog("How much is it   "));

            person.addIncome(person.getPerId(), day, catalog, Income);
            person.update();
        } //Add Expense
        else if (check == 2) {
            double Expense;
            String catalog = "";
            catalog = JOptionPane.showInputDialog("What is your expense :");
            Expense = Integer.parseInt(JOptionPane.showInputDialog("How much is it   "));
            person.addExpense(person.getPerId(), day, catalog, Expense);
            person.update();
        } //Add Save 
        else if (check == 3) {
            double Saving;
            double SavingTotal = 0;
            String catalog = "";

            Saving = Integer.parseInt(JOptionPane.showInputDialog("How much is it "));
            SavingTotal += Saving;
            person.addSave(person.getPerId(), day, catalog, Saving);
            person.update();
        } //History
        else if (check == 4) {
            String x;
            do {
                System.out.println("-----------------------------------------");
                System.out.println("YOUR HISTORY");
                System.out.println("Date                Type           Amount");
                System.out.println("-----------------------------------------");
                List<History> history = person.getHistory();
                if (history != null) {
                    int count = 1;
                    for (History h : history) {
                        if (count++ <= 1) {
                            System.out.println(h.getHistoryDateTime() + "   " + h.getHistoryDescription()
                                    + "           " + h.getAmount());
                        } else {
                            System.out.println(h.getHistoryDateTime() + "   " + h.getHistoryDescription()
                                    + "           " + h.getAmount());
                        }
                    }
                }
                System.out.println("-----------------------------------------");
                System.out.print("Back to menu (0 or back) : ");
                x = sc.next();
            } while (!x.equalsIgnoreCase("back") && !x.equalsIgnoreCase("0"));
        } //Searh
        else if (check == 5) {
            try {
                Connection conn = ConnectionDB.getConnection();
                long a = person.getPerId();
                String NAME = "Salary";
                PreparedStatement ps = conn.prepareStatement(
                        "SELECT * FROM  INCOME WHERE PERID = " + a + "  and CATALOG LIKE '%" + NAME + "%' ");
                ResultSet rec = ps.executeQuery();

                while ((rec != null) && (rec.next())) {
                    System.out.print(rec.getDate("Days"));
                    System.out.print(" - ");
                    System.out.print(rec.getString("CATALOG"));
                    System.out.print(" - ");
                    System.out.print(rec.getDouble("AMOUNT"));
                    System.out.print(" - ");
                }
                ps.close();
                conn.close();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        } //Analy 
        else if (check == 6) {
            String x;
            do {
                DecimalFormat df = new DecimalFormat("##.##");
                double in = person.getIncome();
                double ex = person.getExpense();
                double sum = person.getSumin_ex();
                System.out.println("-----------------------------------------");
                System.out.println("Income : " + df.format((in / sum) * 100) + "%");
                System.out.println("Expense : " + df.format((ex / sum) * 100) + "%");
                System.out.println("\n\n");
                System.out.print("Back to menu (0 or back) : ");
                x = sc.next();
            } while (!x.equalsIgnoreCase("back") && !x.equalsIgnoreCase("0"));
        } //TOTAL
        else if (check == 7) {
            String x;
            do {
                System.out.println("-----------------------------------------");
                System.out.println("TOTALSAVE             TOTAL");
                System.out.println(
                        person.getTotalSave() + " Baht" + "             " + person.getTotal() + " Baht");
                System.out.println("\n\n");
                System.out.print("Back to menu (0 or back) : ");
                x = sc.next();
            } while (!x.equalsIgnoreCase("back") && !x.equalsIgnoreCase("0"));
        } //ALL Summy
        else if (check == 8) {
            String x;
            do {
                DecimalFormat df = new DecimalFormat("##.##");
                double in = person.getIncome();
                double ex = person.getExpense();
                double sum = person.getSumin_ex();
                double a = ((in / sum) * 100);
                double b = ((ex / sum) * 100);
                System.out.println("-----------------------------------------");
                System.out.println("ALL SUMMARY");
                System.out.println("Account: " + person.getPerName());
                System.out.println("");
                System.out.println("Total Save ------------- Total");
                System.out
                        .println(person.getTotalSave() + " Baht               " + person.getTotal() + " Baht");
                System.out.println("");

                System.out.println("INCOME --------------- EXPENSE");
                System.out.println(df.format(a) + "%" + "                  " + df.format(b) + "%");

                System.out.println("-----------------------------------------");
                System.out.println("\n\n");
                System.out.print("Back to menu (0 or back) : ");
                x = sc.next();
            } while (!x.equalsIgnoreCase("back") && !x.equalsIgnoreCase("0"));
        } //LOG OUT 
        else {
            System.out.println("See ya.\n");
            login = false;
            break;
        }
    } while (true);
}

From source file:com.bluexml.tools.miscellaneous.Translate.java

/**
 * @param args/*ww  w  .j  a va  2  s.com*/
 */
public static void main(String[] args) {
    System.out.println("Translate.main() 1");
    Console console = System.console();

    System.out.println("give path to folder that contains properties files");
    Scanner scanIn = new Scanner(System.in);

    try {
        // TODO Auto-generated method stub
        String sWhatever;

        System.out.println("Translate.main() 2");
        sWhatever = scanIn.nextLine();
        System.out.println("Translate.main() 3");

        System.out.println(sWhatever);

        File inDir = new File(sWhatever);

        FilenameFilter filter = new FilenameFilter() {

            public boolean accept(File arg0, String arg1) {
                return arg1.endsWith("properties");
            }
        };
        File[] listFiles = inDir.listFiles(filter);
        for (File file : listFiles) {

            prapareFileToTranslate(file, inDir);

        }

        System.out.println("please translate text files and press enter");
        String readLine = scanIn.nextLine();
        System.out.println("Translate.main() 4");
        for (File file : listFiles) {

            File values = new File(file.getParentFile(), file.getName() + ".txt");
            writeBackValues(values, file);
            values.delete();
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        scanIn.close();
    }

}