JAVA IO流的应用
JAVA IO流的应用
IO流的典型应用
尽管库内存在大量IO流类,可通过多种不同的方式组合到一起,但实际上只有几种方式才会经常用到。然而,必须小心在意才能得到正确的组合。下面这个相当长的例子展示了典型IO配置的创建与使用,可在写自己的代码时将其作为一个参考使用。注意每个配置都以一个注释形式的编号起头,并提供了适当的解释信息。
//: IOStreamDemo.java
// Typical IO Stream Configurations
import java.io.*;
import com.bruceeckel.tools.*;
public class IOStreamDemo {
public static void main(String[] args) {
try {
// 1. Buffered input file
DataInputStream in =
new DataInputStream(
new BufferedInputStream(
new FileInputStream(args[0])));
String s, s2 = new String();
while((s = in.readLine())!= null)
s2 += s + "\n";
in.close();
// 2. Input from memory
StringBufferInputStream in2 =
new StringBufferInputStream(s2);
int c;
while((c = in2.read()) != -1)
System.out.print((char)c);
// 3. Formatted memory input
try {
DataInputStream in3 =
new DataInputStream(
new StringBufferInputStream(s2));
while(true)
System.out.print((char
相关文档:
第八章 异常
异常
两类 错误error 系统内部错误 违例exception 其他编程错误或外在因素】
异常处理机制
抛出异常throw 当不确定为何种异常和不确定怎么处理的时候使用
捕获异常catch
try{}
catch(){}
finally{}为统一出口
fileinputstream类的成员方法read()的功能是每次从相应的(本地为asc2码)文件中读出一个字节 ......
第十章
gui应用程序设计
awt abstractwindow toolkit
gui graphical user interface
组件component
container 容器
window 顶级窗口
panel 接纳其他组件的容器 不能独立存在
必须在其他容器中(如window或applet)
frame是window子类 效果是一个窗口setvisible(true)可见
component
container
window &n ......
简化Java应用程序的打包和发布
发布Java应用程序时你会感到困难?好在Java提供了一系列打包和发布工具,可以显著的简化发布过程
该文章提供了打包Java code的几种方法,我们将会探讨Java manifest 文件,给出用于管理JAR文件所依赖文件、估计跨平台发布所需的CLasspath的合适方法.我也会解释如何使用manifest包版本特性 ......
JAVA读XML:sax,dom,jdom,dom4j的比较以及选择(转)
原文:www.hicourt.gov.cn/homepage/show9_content.asp
SAX: ......