日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

system.setout_Java System类setOut()方法及示例

發布時間:2024/1/8 java 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 system.setout_Java System类setOut()方法及示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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 FileFile file = new File("E://Programs//getProperties().doc");// By using exists() method returns true if file existsSystem.out.println("file existing is = " + file.exists());// Creating an instance of FileOutputStream fosFileOutputStream 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 SetOutMethodException 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()方法及示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。