Java I/O学習標準のI/Oリダイレクト
746 ワード
public class Test{
/*
* I/O
* System.setIn(InputStream)
* System.setOut(PrintStream)
* System.setErr(PrintStream)
*/
public static void main(String[] args) throws IOException {
PrintStream console = System.out;
BufferedInputStream in = new BufferedInputStream(new FileInputStream("/home/estar/Test/a.java"));
PrintStream out = new PrintStream("and.out");
System.setIn(in);
System.setOut(out);
System.setErr(out);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = null;
while ((s = br.readLine()) != null) {
System.out.println(s);
}
out.close();
System.setOut(console);
}
}