system.setout

系统类setOut()方法 (System class setOut() method)

  • setOut() method is available in java.lang package.

    setOut()方法在java.lang包中可用。

  • setOut() method is used to assign again the standard output stream or in other words, this method is used to reassign the standard output stream.

    setOut()方法用于再次分配标准输出流,或者换句话说,该方法用于重新分配标准输出流。

  • The setOut() method is redirected because it does not write the output on the editor.

    setOut()方法被重定向,因为它没有在编辑器上写入输出。

  • The setOut() method does not write the output to the proper JTextArea like setErr() method and it returns null.

    setOut()方法不会像setErr()方法那样将输出写入适当的JTextArea,并且它返回null。

  • This is a static method, so this method is accessible with the class name too.

    这是一个静态方法,因此也可以使用类名访问此方法。

  • setOut() method may throw an exception while writing the output to the standard output stream and the description is given below

    setOut()方法在将输出写入标准输出流时可能会引发异常,下面给出了描述

    SecurityException: In this exception, the checkPermission() method does not allow reassigning of the latest standard output stream when the security manager exists.

    SecurityException:在这种例外情况下,当安全管理器存在时, checkPermission()方法不允许重新分配最新的标准输出流。

Syntax:

句法:

    public static void setOut(PrintStream set_out);

Parameter(s):

参数:

  • set_out – represents the latest standard output stream.

    set_out –代表最新的标准输出流。

Return value:

返回值:

The return type of this method is void, it returns nothing

此方法的返回类型为void ,不返回任何内容

Example:

例:

// Java program to demonstrate the example of
// setOut() method of System Class.
import java.lang.*;
import java.io.*;
public class SetOutMethod {public static void main(String[] args) throws Exception {// Creating an instance of File
File file = new File("E://Programs//getProperties().doc");
// By using exists() method returns true if file exists
System.out.println("file existing is  = " + file.exists());
// Creating an instance of FileOutputStream fos
FileOutputStream fos = new FileOutputStream(file);
System.setOut(new PrintStream(fos));
System.out.println("File Writing Done!!");
}
}

Output

输出量

E:\Programs>javac SetOutMethod.java
E:\Programs>java SetOutMethod
file existing is  = true

Output – if file does not exist

输出–如果文件不存在

E:\Programs>javac SetOutMethod.java
E:\Programs>java SetOutMethod
Exception in thread "main" java.io.FileNotFoundException:
E:/Programs/getProperties().doc (No such file or directory)
at java.base/java.io.FileOutputStream.open0(Native Method)
at java.base/java.io.FileOutputStream.open(FileOutputStream.java:299)
at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:238)
at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:188)
at SetOutMethod.main(SetOutMethod.java:16)

翻译自: https://www.includehelp.com/java/system-class-setout-method-with-example.aspx

system.setout

system.setout_Java System类setOut()方法及示例相关推荐

  1. getenv java_Java System类getenv()方法及示例

    系统类getenv()方法getenv()方法在java.lang包中可用. getenv()方法用于返回键值对中当前环境变量的不可修改Map. 我们将看到什么是环境变量?环境变量是系统相关的外部命名 ...

  2. java super.getclass_Java Class 类 getSuperClass()方法及示例

    Class类getSuperClass()方法getSuperClass()方法在java.lang包中可用. getSuperClass()方法用于返回Class,该Class表示此Class表示的 ...

  3. java long short_Java Long类shortValue()方法与示例

    Long类shortValue()方法shortValue()方法在java.lang包中可用. shortValue()方法用于返回由此Long对象表示的值,该对象转换为short类型(通过强制转换 ...

  4. java annotation class,Java Class类 isAnnotation()方法及示例

    Class类isAnnotation()方法isAnnotation()方法在java.lang包中可用. isAnnotation()方法用于检查此Class对象是否表示注释类型. isAnnota ...

  5. java parsefloat 误差_Java Float类parseFloat()方法与示例

    Float类parseFloat()方法parseFloat()方法在java.lang包中可用. parseFloat()方法用于返回与给定String表示形式相对应的float值,换句话说,我们可 ...

  6. java compareto long_Java Long类compareTo()方法与示例

    Long类compareTo()方法compareTo()方法在java.lang包中可用. compareTo()方法用于在数学上检查该Long对象与给定Long对象的相等性或不相等性,换句话说,可 ...

  7. java getmethod类_Java Class类 getMethod()方法及示例

    Class类getMethod()方法getMethod()方法在java.lang包中可用. getMethod()方法用于返回Method对象,这些对象指示该类的给定公共方法或由此Class对象表 ...

  8. JAVA的infinite_Java Float类isInfinite()方法与示例

    语法:public boolean isInfinite (); public static boolean isInfinite (float value); Float类isInfinite()方 ...

  9. java class getfield_Java Class类 getField()方法及示例

    Class类getField()方法getField()方法在java.lang包中可用. getField()方法用于返回一个Field对象,该对象指示该类的给定公共成员字段或由此Class对象表示 ...

最新文章

  1. python连接sqlserver_python 链接sqlserver 写接口实例
  2. 【Android 逆向】类加载器 ClassLoader ( 启动类加载器 | 扩展类加载器 | 应用类加载器 | 类加载的双亲委托机制 )
  3. MySQL查看与修改编码方式(mysql、数据库、表)
  4. [Silverlight]16进制颜色转ARGB及Color转Int32
  5. java list to byte_java – 将ArrayList转换为byte []
  6. 2016陕西省赛 Rui and her functions
  7. 华为7c手机怎么恢复出厂设置_华为手机越用越卡,恢复出厂设置真有用?别乱来,看完就明白了!...
  8. J-Link软件和文档包的版本发行说明(1)[V3.00d ~ V4.94j版本]
  9. 夫妻宫十星所暗示的未来另一半
  10. Docker 基于centos7制作jdk8 镜像并添加字体; 运行jar 包
  11. 前端字体图标的使用总结
  12. 银行利息计算公式推导(存款,贷款)
  13. 微信公众号开发__微信网页授权并获取用户基本信息(是否关注公众号、头像、昵称等)
  14. 低速接口之SPI接口,分类,四种模式,特点
  15. KingbaseES人大金仓学习
  16. 几个比较新的恶意程序……AntiVir全报,kaspersky保持沉默的时候多
  17. xo存放年限_XO酒的保质期怎么辨别 ?
  18. unity沙子堆积_unity游戏逼真沙子和白雪粒子特效渲染创建插件Basic Sand amp; Snow 1.0 - 素材巷...
  19. @Autowired的这些骚操作,你都知道吗
  20. Tomcat 部署 war包

热门文章

  1. Unifying Task-oriented Knowledge Graph Learning and Recommendation
  2. android 第三方社区,从友盟微社区看Android第三方SDK架构实践
  3. 惠海半导体H7230直接替换BP1371 BP1361方案设计
  4. tinode客户端安卓版编译手账
  5. rsync来实现文件同步
  6. python自动测试相机_OpenCV-Python 相机校准 | 四十九
  7. 每日学一个设计模式16——仲裁者模式
  8. 什么叫手机或设备的ID
  9. 干货!如何快速拥有自己的商城APP
  10. 流程图中省略的图表怎么表示_如何将流程图和图表添加到Google文档或幻灯片