当前位置:网站首页>Standard input / output stream
Standard input / output stream
2022-07-18 22:31:00 【Lan Zhou Qianfan】
We usually use Scanner The following method is used to input data from the keyboard , But it is also a very meaningful thing to find out its essence .
Its bottom layer still uses byte input stream .
In this way, it is connected with the knowledge of flow .
Standard output stream
public class PrintStreamextends FilterOutputStreamimplements Appendable, Closeable
PrintStream Added functionality for other output streams , So that they can easily print various data value representations . It also provides two other functions . Unlike other output streams ,PrintStream Never throw IOException; It is , Exceptions can only be set through checkError The internal logo of the method test . in addition , In order to automatically refresh , You can create a PrintStream; This means that you can write byte Array is automatically called after flush Method , One of the println Method , Or write a newline character or byte (‘\n’). PrintStream All characters printed are converted to bytes using the platform's default character encoding . In the case of writing characters instead of bytes , You should use PrintWriter class .
Some construction methods
PrintStream(File file) Create a new print stream with the specified file and no automatic line refresh . PrintStream(File file, String csn) Create a new print stream with the specified file name and character set without automatic line refresh . PrintStream(OutputStream out) Create a new print stream . PrintStream(OutputStream out, boolean autoFlush) Create a new print stream . PrintStream(OutputStream out, boolean autoFlush, String encoding) Create a new print stream . PrintStream(String fileName) Create a new print stream with the specified file name without automatic line refresh . PrintStream(String fileName, String csn) Create a new print stream with the specified file name and character set without automatic line refresh .
So the message we get is , We can determine whether to refresh automatically according to the Boolean value in the parameter , In addition, you can also specify the encoding .
This is the same as the standard input stream System The format defined in the class is the same . Bottom words , In fact, it is also a byte stream . Simply look at how to use .
// Standard output stream
PrintStream out = System.out;
out.print("hello");// Output on the console But you can also output to a file , That is to input data into a file .
// Byte print stream
PrintStream ps = new PrintStream("E:\\java_doc\\src\\io_demo\\jgdabc.txt");
ps.write(97);// Use parent methods
ps.print(97);// Use your own method
ps.close();
// Character print stream
PrintWriter pW = new PrintWriter("E:\\java_doc\\src\\io_demo\\jgdabc.txt");
pW.write("hello");
pW.flush();
pW.println("Hello");
pW.flush();
PrintWriter pw = new PrintWriter(new FileWriter("E:\\java_doc\\src\\io_demo\\jgdabc.txt"),true);// Will automatically refresh
pw.println("Hello");
pw.println("world"边栏推荐
- KDD 2017 | metapath2vec: scalable representation learning of heterogeneous graphs
- A New Optimizer Using Particle Swarm Theory
- Huawei od search for the same substring
- ArrayList源码解析
- DCAT admin code generator application (re edit)
- Towhee daily model weekly report
- Spark streaming Programming Guide
- 开发者分享|手写算子没那么难,教你用MindSpore实现自适应平均池化算子!
- Timesformer: can you understand video by transformer alone? Another attack of attention mechanism!
- Quickly solve the problem of error or garbled code when inserting Chinese data into mysql
猜你喜欢

After reading this article, I will teach you to play with vulnhub, the penetration test target machine -- evilbox one

Domestic light! High score spatiotemporal representation learning model uniformer

Which brand of Bluetooth headset is good at noise reduction? 2022 noise reduction headset ranking

How to solve the problem of 8080 port being occupied? Win11 8080 port occupied solution

LINGO求解分段函数最大(小)值
![[AI Engineering] 02-ai Engineering](/img/b0/71a9a792ced8b32289e48ca36f77ae.jpg)
[AI Engineering] 02-ai Engineering

Wonderful review of usability sig technology sharing activities on July 7

The 100 billion yuan universe market is the new driving force of soul and Yingke

new操作符具体做了什么,面试

Timesformer: can you understand video by transformer alone? Another attack of attention mechanism!
随机推荐
大疆校招测评题--循环赛问题
Dajiang school recruitment evaluation question -- round robin problem
Dcat Admin 代码生成器应用(重新编辑)
Accessing local variables in anonymous inner classes
8080端口被占用怎么解决?Win11 8080端口被占用解决方法
[UCOS III source code analysis] - Software Timer
TimeSformer: 只靠 Transformer 就能理解视频?注意力机制的又一次进击!
华为od-寻找相同子串
Developers share | handwriting operator is not so difficult. I'll teach you to use mindspire to realize adaptive average pooling operator!
The real working state of the 21st graduates within one year after graduation
【部署】Redis
Opengauss database
C language - array
How to record sound on win11 screen? Win11 method of recording screen video with sound
Switching mode converter resource scheme of mp1655gg-z mps/ American core MOSFET
技術幹貨| MindSpore新一代自主研發分子模擬庫:Mind-Sponge
J-dict-select-tag drop-down box failure solution
开源十问, 社区新人快速上手指南
Leetcode 1309. Decode letter to integer mapping (yes, once)
WTL first window