Java on the machine lab report (2)

First, a brief description of the task

java in a variety of ways to read writing file
1, bytes read write contents of the file
2, character by character read write file contents
3, a row read write file content
4, Random Read Write file content

Stream is an abstract concept. When the Java program needs to read data from a data source, it will open a stream to the data source. The data source may be a file, memory, network, or the like. Similarly, when the program needs to output data to the same destination will open a stream, the destination data may be a file, memory, network, or the like. Flow is created in order to more easily handle the input and output data.

Second, the problems and solutions

3.1 operating results

Test1

 

Test2

 

Test3

 

3.2 & 3.3 operating results

3.2

 

3.3

 

to sum up:

The origin of the character stream: since different coded data, and streaming objects with the efficient operation of the character. When in fact essentially based on the read byte stream, to check specified code table.

 

 The difference between byte streams and character streams:

Different reader unit: byte stream byte ( 8bit) units of the character stream in characters, the characters according to the code table mapping, a plurality of bytes may be read.

Different processed: byte stream can handle all types of data (such as images, AVI, etc.), the character stream can handle the type of character data.

Byte stream: one is read into or read 8-bit binary.

Character stream: once read in or out is 16-bit binary.

 

设备上的数据无论是图片或者视频,文字,它们都以二进制存储的。二进制的最终都是以一个8位为数据单元进行体现,所以计算机中的最小数据单元就是字节。意味着,字节流可以处理设备上的所有数据,所以字节流一样可以处理字符数据。

 

结论:只要是处理纯文本数据,就优先考虑使用字符流。 除此之外都使用字节流。

 

输入流和输出流

 

输入流只能进行读操作,输出流只能进行写操作,程序中需要根据待传输数据的不同特性而使用不同的流。

 

存在问题:3.3中26行out.write(tBuffer); 报错

原因是:The method write in the type OutputStreamWriter is not applicable for the arguments(StringBuffer)

问题解决:改为out.write(tBuffer.toString());

public String toString()返回该对象的字符串表示。通常,ToString方法会返回一个"以文本方式表示"此对象的字符串。

Guess you like

Origin www.cnblogs.com/ku1274755259/p/11108534.html