?? writetoprocess.java
字號:
import java.util.*;
import java.io.*;
/**
* Description:
* <br/>Copyright (C), 2005-2008, Yeeku.H.Lee
* <br/>This program is protected by copyright laws.
* <br/>Program Name:
* <br/>Date:
* @author Yeeku.H.Lee kongyeeku@163.com
* @version 1.0
*/
public class WriteToProcess
{
public static void main(String[] args)
{
PrintStream ps = null;
try
{
//運行java ReadStandard命令,返回運行該命令的子進程
Process p = Runtime.getRuntime().exec("java ReadStandard");
//以p進程的輸出流創建PrintStream對象
//這個輸出流對本程序是輸出流,對p進程則是輸入流)
ps = new PrintStream(p.getOutputStream());
//向ReadStandard程序寫入內容,這些內容將被ReadStandard讀取
ps.println("普通字符串");
ps.println(new WriteToProcess());
}
catch (IOException ex)
{
ex.printStackTrace();
}
finally
{
if (ps != null)
ps.close();
}
}
}
//定義一個ReadStandard類,該類可以接受標準輸入,
//并將標準輸入寫入out.txt文件。
class ReadStandard
{
public static void main(String[] args) throws Exception
{
//使用System.in創建Scanner對象,用于獲取標準輸入
Scanner sc = new Scanner(System.in);
PrintStream ps = new PrintStream(
new FileOutputStream("out.txt"));
//增加下面一行將只把回車作為分隔符
sc.useDelimiter("\n");
//判斷是否還有下一個輸入項
while(sc.hasNext())
{
//輸出輸入項
ps.println("鍵盤輸入的內容是:" + sc.next());
}
ps.close();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -