复习一下 IO
Byte Streams
http://java.sun.com/docs/books/tutorial/essential/io/bytestreams.html
public class CopyBytes {
public static void main(String[] args) throws IOException {
FileInputStream in = null;
FileOutputStream out = null;
try {
in = new FileInputStream("xanadu.txt");
out = new FileOutputStream("outagain.txt");
int c;
while ((c = in.read()) != -1) {
out.write(c);
}
} finally {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
}
}
}
2个小问题
1.Always Close Streams
finally块释放资源,为什么要判断 in != null ?
不是因为 in 对象可能前面自己释放了,而是因为发生异常的情况可能是2个文件可能发生一个打开一个不打开,或者2个都无法打开的情况,那么此时 in 仍然是 null ,并没有改变,所以需要判断。
in.close();是必须执行的部分,所以有必要放在finally块里,否则可能导致资源泄漏。
2.When Not to Use Byte Streams
何时不使用byte流
byte流真的很底层,太底层的不健康。对于包含字符的数据,其实最好的实现是基于字符的流,但为什么这里需要讨论byte,因为所有的流都基于byte流
分享到:
相关推荐
* This file implements the basic I/O fucntions that access a register of W5300( IINCHIP_REG). * * Revision History : * ---------- ------- ----------- ---------------------------- * Date Version ...
SIMATIC ET 200S 分布式 I/O IM151-1 BASIC 接口模块 (6ES7151-1CA00-0AB0)[手册]pdf,
用Visual Basic实现对系统IO端口的操作.vb
It provides example driver code that demonstrates the proper initialization, boot up and basic I/O operation of i.MX 6 peripherals and controllers. This code can be implemented into test suites or ...
其中包括Resource Template Functions and Operations,Basic I/O Operations,Formatted and Buffered I/O Operations,viPrintf Overloads,viSPrintf Overloads,viScanf Overloads,viSScanf Overloads,Memory ...
Basic and advanced I/O Concepts Binary I/O and the new buffer classes Memory mapped files and file locking Character I/O: encoding, decoding and transforming character data Regular Expressions ...
formatted I/O library, and the basic I/O system. • Create and use local file systems. • From VxWorks, access file systems on remote machines. • Reconfigure VxWorks, linking in user-defined code. v ...
from and writing to files, along with other basic file I/O operations. The chapter culminates with a discussion on how the Linux kernel implements and manages files. Chapter 3, Buffered I/O This ...
Basic I/O operations, such as reading from and writing to files Advanced I/O interfaces, memory mappings, and optimization techniques The family of system calls for basic process management Advanced ...
covers reading from and writing to files, along with other basic file I/O operations. The chapter culminates with a discussion on how the Linux kernel implements and manages files. Chapter 3, Buffered...
本文介绍了在Visual Basic6.0环境下采用“自上而下地总体规划,自下而上地应用开发”的策略开发一个管理信息系统的过程。通过分析某一学校学生管理的不足,创建了一套行之有效的计算机管理学生的方案。文章介绍了...
Also demonstrates the use of MS Rich TextBox 6.0 control and basic I/O of text (data) files. A detailed Word 6.0 "ReadMe" file is included.<END><br>2,calc2.zip A very Simple Calculator, i made ...
Java Language Features: With Modules, Streams, Threads, I/O, and Lambda Expressions Work with essential and advanced features of the Java programming language such as Java modules development, lambda ...
PART I: CORE TECHNOLOGIES 1 Overview ...................................................................................................... 3 1.1 Introduction ............................................
<END><br>58,dpp.zip D++ is a fully function scripting language the supports basic I/O, if's, expressions, and tons more! This language can also combine itself with a DLL (source included) and ...
Terminal-BASIC是一种类似于BASIC的语言解释器,可在一组单板嵌入式系统(即... *使用vt100命令在不同的I / O设备上工作; *在具有多个I / O设备的系统上可以用作简单的分时系统; *用于播放和调试的静态Linux构建;
第一部分 传统网络API 第1章 NetBIOS 第2章 重定向器 第3章 邮槽 第4章 命名管道 第二部分 Winsock API 第5章 网络原理和协议 第6章 地址家族和名字解析 第7章 Winsock基础 第8章 Winsock I/O方法 第9章 套接字选项...
Go provides excellent support for both basic and complex I/O. The recipes in this chapter will explore common Go interfaces to deal with I/O and show how to make use of them. The Go standard library...
自动化技术 自动化技术 工业自动化系统 SIMATIC PLC 高级控制器 S7-1500 I/O modules Fail-Safe Digital/Analog I/O Modules 自动化技术 自动化技术 工业自动化系统 SIMATIC PLC 高级控制器 S7-1500 I/O modules ...