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
相关文档:
一:准备 www.savarese.org download
1. rocksaw-1.0.0-src.tar.gz
2. vserv-tcpip-0.9.2-src.tar.gz
二:编译源文件得到jar包 使用Ant
1. build vserv-tcpip-0.9.2-src
在vserv-tcpip-0.9.2目录下面建一个tests目录,然后在cmd窗口下进入 ......
第八章 异常
异常
两类 错误error 系统内部错误 违例exception 其他编程错误或外在因素】
异常处理机制
抛出异常throw 当不确定为何种异常和不确定怎么处理的时候使用
捕获异常catch
try{}
catch(){}
finally{}为统一出口
fileinputstream类的成员方法read()的功能是每次从相应的(本地为asc2码)文件中读出一个字节 ......
著作权保护声明
Chinaitlab高度重视知识产权保护并遵守中国各项知识产权法律、法规和具有约束力规范性文件。根据法律、法规和规范性文件要求,Chinaitlab
制定了旨在保护知识产权权利人合法权益的措施和步骤,当著作权人和/或依法可以行使著作权的权利人(以下简称“权利人”)发现在本站网页的内容或下
&nbs ......
1.Prototyping: in general (Enterprise) Java projects start with evaluation which frameworks to use. This can take from few hours, to several months (although these times are hopefully over). Java EE 6 comes with “one stop shopping”. You can download Java EE 6 with the IDE (eclipse, netbe ......
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 将汉字转化为全拼
*/
public class CnToSpell {
private static Map<String, Integer> spellMap = null;
// 存放生僻字和其拼音的Map
private static Map<Characte ......