package iodemo;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Scanner;
public class ReadStandard {
/**
* @param args
* @throws FileNotFoundException
*/
public static void main(String[] args) throws FileNotFoundException {
Scanner sc = new Scanner(System.in);
PrintStream ps = new PrintStream(new FileOutputStream("d:\\a\\out3.txt"));
sc.useDelimiter("\n");//只使用换行作为唯一分隔符
while(sc.hasNext()) {
ps.print(sc.next());
}
if(ps != null) {
ps.close();
sc.close();
}
}
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Scanner;
public class ReadStandard {
/**
* @param args
* @throws FileNotFoundException
*/
public static void main(String[] args) throws FileNotFoundException {
Scanner sc = new Scanner(System.in);
PrintStream ps = new PrintStream(new FileOutputStream("d:\\a\\out3.txt"));
sc.useDelimiter("\n");//只使用换行作为唯一分隔符
while(sc.hasNext()) {
ps.print(sc.next());
}
if(ps != null) {
ps.close();
sc.close();
}
}
}
————————————————————————————————————————————————————————
package iodemo;
import java.io.IOException;
import java.io.PrintStream;
public class WriteToProcess {
/**
* @param args
*/
public static void main(String[] args) {
PrintStream ps = null ;
try {
Process p = Runtime.getRuntime().exec("java ReadStandard");
ps = new PrintStream(p.getOutputStream());//对于子进程来说是输入流
ps.print("进程WriteToProcess 写东西到子进程 ReadStandard");
ps.print(new WriteToProcess());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if(ps != null) {
ps.close();
}
}
}
}