标准输入流和标准输出流

标准输入输出流

基本介绍:

System:构造器是私有的

类型默认设备
System.in 标准输入InputStream键盘
System.out 标准输出PrintStream显示器

继承关系图

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-YYNBrEW8-1646658802129)(E:\Typora笔记\java笔记\img\image-20220307092411900.png)]

常用方法

Modifier and TypeMethod and Description
static voidarraycopy(Object src, int srcPos, Object dest, int destPos, int length) 将指定源数组中的数组从指定位置复制到目标数组的指定位置。
static StringclearProperty(String key) 删除指定键指定的系统属性。
static Consoleconsole() 返回与当前Java虚拟机关联的唯一的Console对象(如果有)。
static longcurrentTimeMillis() 返回当前时间(以毫秒为单位)。
static voidexit(int status) 终止当前运行的Java虚拟机。
static voidgc() 运行垃圾回收器。
static Map<String,String>getenv() 返回当前系统环境的不可修改的字符串映射视图。
static Stringgetenv(String name) 获取指定环境变量的值。
static PropertiesgetProperties() 确定当前的系统属性。
static StringgetProperty(String key) 获取指定键指示的系统属性。
static StringgetProperty(String key, String def) 获取指定键指示的系统属性。
static intidentityHashCode(Object x) 返回与默认方法hashCode()返回的给定对象相同的哈希码,无论给定对象的类是否覆盖了hashCode()。
static StringlineSeparator() 返回与系统相关的行分隔符字符串。
static voidsetErr(PrintStream err) 重新分配“标准”错误输出流。
static voidsetIn(InputStream in) 重新分配“标准”输入流。
static voidsetOut(PrintStream out) 重新分配“标准”输出流。
static voidsetProperties(Properties props) 将系统属性设置为 Properties参数。

案例:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-qPnzahkG-1646658802131)(E:\Typora笔记\java笔记\img\image-20220306195635037.png)]

注意是:一定要理解下面代码:// public final static InputStream in = null; 的属性的类型是 InputStream//public final static PrintStream out = null; 的属性的类型是 PrintStream

package IO_.fileInputStream.standard;

import java.util.Scanner;

/**
 * @author: 海康
 * @version: 1.0
 */
public class InputAndOutput {
    public static void main(String[] args) {
        // public final static InputStream in = null; 的属性的类型是 InputStream
        // System.in 的编译类型是:InputStream
        // System.in 的运行类型是:BufferInputStream
//        System.in

        //public final static PrintStream out = null; 的属性的类型是 PrintStream
        // System.out 的编译类型是:PrintStream
        // System.out 的运行类型是:PrintStream
//        System.out

        Scanner scanner = new Scanner(System.in);
        // Scanner 是标准输入 键盘接收数据
        System.out.println("请从键盘输入一个整数:");
        int i = scanner.nextInt();
        System.out.println("输入的整数是= " + i);
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值