Console read and write Utils : Console « Development Class « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JavaFX
25.JDK 6
26.JDK 7
27.JNDI LDAP
28.JPA
29.JSP
30.JSTL
31.Language Basics
32.Network Protocol
33.PDF RTF
34.Reflection
35.Regular Expressions
36.Scripting
37.Security
38.Servlets
39.Spring
40.Swing Components
41.Swing JFC
42.SWT JFace Eclipse
43.Threads
44.Tiny Application
45.Velocity
46.Web Services SOA
47.XML
Java » Development Class » Console 




Console read and write Utils
        
//package org.loon.framework.game.simple.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/**
 
 * Copyright 2008 - 2009
 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 
 * http://www.apache.org/licenses/LICENSE-2.0
 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 
 * @project loonframework
 @author chenpeng
 * @email:ceponline@yahoo.com.cn
 @version 0.1
 */
final public class ConsoleUtils {

  private static BufferedReader reader;

  static {
    reader = new BufferedReader(new InputStreamReader(System.in));
  }

  private static String readData() {
    try {
      return reader.readLine();
    catch (IOException ex) {
      return null;
    }
  }

  public static String readString() {
    return readData();
  }

  public static int readInteger() {
    return Integer.parseInt(readData());
  }

  public static float readFloat() {
    return Float.parseFloat(readData());
  }

  public static double readDouble() {
    return Double.parseDouble(readData());
  }

  public static long readLong() {
    return Long.parseLong(readData());
  }

  public static char[] readChars() {
    return readData().toCharArray();
  }

  public static String readSubstring(int start, int end) {
    return readData().substring(start, end);
  }

  public static int execute(String commandthrows InterruptedException,
      IOException {
    Process process = Runtime.getRuntime().exec(command);
    process.waitFor();
    return process.exitValue();
  }

  public static Process exec(String command[]boolean stop)
      throws InterruptedException, IOException {
    Process p = Runtime.getRuntime().exec(command);
    if (stop)
      p.waitFor();
    return p;
  }

  public static Process exec(String exePath, List files, boolean stop)
      throws InterruptedException, IOException {
    List filePaths = new ArrayList();
    filePaths.add(exePath);
    for (int i = 0; i < files.size(); i++) {
      File file = (Filefiles.get(i);
      filePaths.add(file.getPath());
    }
    String command[] (String[]) filePaths.toArray(new String[filePaths
        .size()]);
    return exec(command, stop);
  }

  public static Process exec(String command, boolean stop)
      throws InterruptedException, IOException {
    return exec(new String[] { command }, stop);
  }
}

   
    
    
    
    
    
    
    
  














Related examples in the same category
1.Turn System.out into a PrintWriterTurn System.out into a PrintWriter
2.Output to standard output and standard error; and input from standard input.Output to standard output and standard error; and input from standard input.
3.VarArgsDemo - show 1.5 variable argumentsVarArgsDemo - show 1.5 variable arguments
4.How to read from standard inputHow to read from standard input
5.How to deal with the console parametersHow to deal with the console parameters
6.Read input from consoleRead input from console
7.Command line input
8.Read an int from Standard Input
9.Read an int from Standard Input, using 1.5
10.SimpleCalc -- simple calculator using 1.5 java.util.Scanner
11.Show use of Argv to get an integer value from command lineShow use of Argv to get an integer value from command line
12.Java program to calculate the area of a circleJava program to calculate the area of a circle
13.Java program to demonstrate menu selectionJava program to demonstrate menu selection
14.Utility class for printing aligned columns of text
15.Processing the command line
16.A representation of the command line arguments passed to a Java class' main(String[]) method
17.Helper class for storing long command lines inside temporary file.
18.CommandLine Parser
19.This parses command line arguments optimized for ease of programmer use.
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.