1.1.1. Where Do Streams Come From?
来源:互联网 发布:易语言源码网站 编辑:程序博客网 时间:2024/04/25 04:41
The first source of input most programmers encounter is System.in. This is the same thing as stdin in Cgenerally some sort of console window, probably the one in which the Java program was launched. If input is redirected so the program reads from a file, then System.in is changed as well. For instance, on Unix, the following command redirects stdin so that when the MessageServer program reads from System.in, the actual data comes from the file data.txt instead of from the console:
% java MessageServer < data.txt
The console is also available for output through the static field out in the java.lang.System class, that is, System.out . This is equivalent to stdout in C parlance and may be redirected in a similar fashion. Finally, stderr is available as System.err . This is most commonly used for debugging and printing error messages from inside catch clauses. For example:
try { //... do something that might throw an exception}catch (Exception ex) { System.err.println(ex); }
Both System.out and System.err are print streamsthat is, instances of java.io.PrintStream. These will be discussed in detail in Chapter 7.
Files are another common source of input and destination for output. File input streams provide a stream of data that starts with the first byte in a file and finishes with the last byte in that file. File output streams write data into a file, either by erasing the file's contents and starting from the beginning or by appending data to the file. These will be introduced in Chapter 4.
Network connections provide streams too. When you connect to a web server, FTP server, or some other kind of server, you read the data it sends from an input stream connected from that server and write data onto an output stream connected to that server. These streams will be introduced in Chapter 5.
Java programs themselves produce streams. Byte array input streams, byte array output streams, piped input streams, and piped output streams all move data from one part of a Java program to another. Most of these are introduced in Chapter 9.
Perhaps a little surprisingly, GUI components like TextArea and JTextArea do not produce streams. The issue here is ordering. A group of bytes provided as data for a stream must have a fixed order. However, users can change the contents of a text area or a text field at any point, not just at the end. Furthermore, they can delete text from the middle of a stream while a different thread is reading that data. Hence, streams aren't a good metaphor for reading data from GUI components. You can, however, use the strings they do produce to create a byte array input stream or a string reader.
- 1.1.1. Where Do Streams Come From?
- 读书摘要 Where do disruptive ideas come from?
- WHERE DOES CREATIVITY COME FROM?
- where bond0 device come from
- Where must the puma have come from?
- Microsoft Access 名字的由来(Where did the name for Microsoft Access come from?)
- B.1. Where From Here?
- [机器学习入门] 李宏毅机器学习笔记-4(Where does the error come from ;误差分析)
- Oracle X$ tables – Part 1 – Where do they get their data from?
- where do i belong
- Where do I belong
- where do I turn?
- from which from where
- something come from 工资汇总表
- errno(come from baidu)
- Come from my OS teacher
- Rectangle Area ---come from leetcode
- getmsg, getpmsg - receive next message from a STREAMS file (STREAMS)
- switch 中嵌套 while之妙用
- java时间生成格式解决方法
- 浮点数
- helix server介绍及架设网络电视
- string to float
- 1.1.1. Where Do Streams Come From?
- windows2003优化小贴士
- 数据库设计
- 关于java的事务处理和举例
- 闲置了好久
- oracle中的函数据
- java 数据库 连接池
- .Net 使用 Intercom OP 调用 Excel 实现报表
- eclipse提示JVM版本太低