/*
 * Created on 2005-5-12
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.chapter2;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.InputStreamReader;

/**
 * @author Administrator
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class CallOtherApp {

	public static void main(String[] args) {
		/*
		 * Process process; try { process = Runtime.getRuntime().exec("cmd /c
		 * start excel java.xls"); } catch (IOException e) {
		 * e.printStackTrace(); }
		 */
// 		String tmp = "abcdefghijklmnopqrstuvwxyz";
// 		byte b[] = tmp.getBytes();
// 		ByteArrayInputStream input1 = new ByteArrayInputStream(b);
// 		ByteArrayInputStream input2 = new ByteArrayInputStream(b,0,3);
// 		System.out.println(b[0]);
// 		System.out.println(input1);
// 		System.out.println(input2);
		String tmp = "abc";
		byte b[] = tmp.getBytes();
		ByteArrayInputStream in = new ByteArrayInputStream(b);
		for (int i = 0; i < 2; i++) {
			int c;
			while ((c = in.read()) != -1) {
				if (i == 0) {
					System.out.print((char) c);
				} else {
					System.out.print(Character.toUpperCase((char) c));
				}
			}
			System.out.println();
			in.mark(4);
			in.reset();
		}
//		CallOtherApp.executePing("127.0.0.1");
	}

	public static void executePing(String dest) {
// 		String cmd = "ping " + dest; // 命令字符串
		String cmd = "help";
		Process process;
		System.out.println(cmd);
		try {
			process = Runtime.getRuntime().exec(cmd); // 直接执行shell的ping程序
			// 取得子进程的输出
			BufferedReader reader = new BufferedReader(new InputStreamReader(
					process.getInputStream()));
			String str;
			while ((str = reader.readLine()) != null) {
				System.out.println(str);
			}
			try {
				process.waitFor();
			} catch (InterruptedException e) {
				System.err.println("process was interrupted");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
