1. 程式人生 > 資訊 >位元組跳動旗下 Ohayoo 遊戲平臺:積極落實未成年人遊戲防沉迷最新規定

位元組跳動旗下 Ohayoo 遊戲平臺:積極落實未成年人遊戲防沉迷最新規定

1、列印流基本使用

package demo02;

import org.junit.Test;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;

/**
 * @description: demo10
 * @author: liuyang
 * @create: 2021-09-06 22:27
 */
public class Demo10 {
    /**
     * 重定向System.out列印流
     
*/ @Test public void test1() { FileOutputStream fileOutputStream = null; PrintStream ps = null; try { fileOutputStream = new FileOutputStream("text5.txt"); ps = new PrintStream(fileOutputStream, true); System.setOut(ps); System.out.println(
"hello,我是中國人"); } catch (FileNotFoundException e) { e.printStackTrace(); } finally { try { if (ps != null) { ps.close(); } } catch (Exception e) { e.printStackTrace(); } } }
/** * 列印流PrintStream */ @Test public void test2() { FileOutputStream fileOutputStream = null; PrintStream ps = null; try { fileOutputStream = new FileOutputStream("text5.txt"); ps = new PrintStream(fileOutputStream, true); ps.print("你們好"); } catch (FileNotFoundException e) { e.printStackTrace(); } finally { try { if (ps != null) { ps.close(); } } catch (Exception e) { e.printStackTrace(); } } } /** * 列印流:PrintWriter */ @Test public void test3() { FileOutputStream fileOutputStream = null; PrintWriter pw = null; try { fileOutputStream = new FileOutputStream("text5.txt"); pw = new PrintWriter(fileOutputStream, true); pw.print("你們好嗎?"); } catch (FileNotFoundException e) { e.printStackTrace(); } finally { try { if (pw != null) { pw.close(); } } catch (Exception e) { e.printStackTrace(); } } } }
相識是緣