您的位置:首页 > 其它

[IO]——重定向

2016-04-09 14:44 232 查看
/**
* 三个常量
* system.in 输入流 键盘输入
* system.out输出流 控制台输出
* system.err
* ---》重定向
* setin(),setout(),seterr()
* filedescriptor.in   filedescriptor.out
* @author Administrator
*
*/
public class systemDemo {
public static void main(String[] args) throws FileNotFoundException {
//test2();
//test1();
//重定向
System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream("E:/others/qqqq.txt")),true));//自动刷新
System.out.println("加油!");//控制台--》文件
//回控制台
System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.out)),true));//自动刷新
System.out.println("come on !");
}
//从文件输入
public static void test2() throws FileNotFoundException{
InputStream is=System.in;//键盘输入
is=new BufferedInputStream(new FileInputStream("E:/others/qqqq.txt"));
Scanner sc=new Scanner(is);
System.out.println("请输入 :");
System.out.println(sc.nextLine());
}
public static void test1(){
System.out.println("中国");
System.err.println("China");//打印错误信息

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  IO 重定向