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
相关文档:
第十章
gui应用程序设计
awt abstractwindow toolkit
gui graphical user interface
组件component
container 容器
window 顶级窗口
panel 接纳其他组件的容器 不能独立存在
必须在其他容器中(如window或applet)
frame是window子类 效果是一个窗口setvisible(true)可见
component
container
window &n ......
遇到一个java编程面试题,当时没有写出来,回来仔细想了想,写出答案,一共以后参考!
要求:将字符串"I am a good student."转换成"student. good a am I"
java代码为:
public class Application
{
private String s;
public void setS(String s)
{
s=s;
}
public S ......
LSParserFilter---载入与保存
应用org.w3c.dom 实现XML的载入与保存实例
/**
* 实现DOM3的LS(Load & Save)功能
*
* @author S.Well
* @see org.w3c.dom.DOMErrorHandler
* @see org.w3c.dom.ls.LSParserFilter
*/
public class XML_LS implements DOMErrorHandler, LSParserFilter {
private static ......
一、面向对象的特征有哪些方面
1.抽象:
抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方面。抽象并不打算了解全部问题,而只是选择其中的一部分,暂时不用部分细节。抽象包括两个方面,一是过程抽象,二是数据抽象。
2 ......