Java 输入输出流全解析
在 Java 编程中,输入输出流是非常重要的概念,它们为数据的读取和写入提供了强大而灵活的机制。下面我们将详细探讨输入输出流的相关知识,包括输入流的使用、输出流的操作以及过滤流的功能。
1. Java 输入流的使用:FileInputStreamDemo 示例
首先,我们来看一个简单的 Java 输入流示例 FileInputStreamDemo ,它展示了如何使用 FileInputStream 从文件中读取数据。以下是示例代码:
if (args.length != 1)
{
System.err.println ("Syntax - FileInputStreamDemo file");
return;
}
try
{
// Create an input stream, reading from the specified file
InputStream fileInput = new FileInputStream ( args[0] );
// Read the first byte of data
int data = fileInput.read();
// Repeat : until end of file (EOF) reached
while (data != -1)
{
// Send byte to standard output
System.out.write (
超级会员免费看
订阅专栏 解锁全文
5389

被折叠的 条评论
为什么被折叠?



