java学习笔记
最近学习java的IO操作,现整理如下
1 输入输出
java的库将程序与输入有关的类都从InputStream继承,与输出有关的类都从OutStream继承。
以前没有掌握的相关类 SequenceInputStream 将两个或更多的inputStream 转换成单个对象使用。
2 增添属性和有用的接口
装饰器 : 利用层次化对象动态透明的增加单个对象的能力的做法叫做“装饰器”
3 输入
对一个文件进行输入操作,需要一个FileInputStream 对象,为提高速度需要对文件进行缓冲处理 BufferedInputStream ,为了以格式化的形式读取数据,我们使用了DataInputStream 来进行处理。
DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(args[0])));
4 快速文件输入
class InFile extends DataInputStream {
public InFile(String fileName) throws FileNotFoundException{
super(new BufferedInputStream(new FileInputStream(fileName)));
}
public InFile(File file) throws FileNotFoundException{
super(new BufferedInputStream(new FileInputStream(file.getPath())));
}
}
这样设计可以避免每次重复够造 。
同样快速文件输出可以按照上述的格式进行构造。
5 Reader Writer
inputstream 是字节流 ,二reader是字符流 传递unicode 。
要使用readLine()应该使用BufferedReader ,二不应该再使用DataInputStream
6 重导向标准IO package cn.bupt.io;
import java.io.*;
public class Redirect {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
BufferedInputStream in = null ;
try {
in = new BufferedInputStream(new FileInputStream(args[0]));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
PrintStream out = null ;
try {
out = new PrintStream(new BufferedOutputStream(new FileOutputStream(args[1]))) ;
} catch (FileNotFoundException e) {
e.printStackTrace();
}
System.setIn(in) ;
System.setOut(out) ;
System.setErr(out) ;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = null ;
try {
whil
相关文档:
最近有网友问:如何让一个JAR文件随JVM启动时运行?java.exe是不能够做成这样的,不过可以自己定制java.exe,定制java.exe在如下情况有用:
1.不想程序的进程名显示为java.exe
2.希望程序双击就可以运行。
下面是一段示例代码:
// JVM_CPP.cpp : Defines the entry point for the console application.
//
#include ......
inkfish翻译,请勿商业性质转载,转载请注明来源(http://blog.csdn.net/inkfish
)。本文是我学习JUEL同时,对原网站进行的简单的翻译,原网站地址:http://juel.sourceforge.net/
JUEL
是统一表达式语言(Unified Expression Language
, EL
)的一个实现,是JSP 2.1
标准(JSR-245
)的一部分,已经作为Ja ......
要想学好Java,首先要知道Java的大致分类。我们知道,自从Sun推出Java以来,就力图使之无所不包,所以Java发展到现在,按应用来分主要 分为三大块:J2SE,J2ME和 J2EE,这也就是Sun ONE(Open Net Environment)体系。J2SE就是Java2的标准版,主要用于桌面应用软件的编程;J2ME主要应用于嵌入是系统开发,如手机和PDA的编 程; ......
一、
IO
流的三种分类方式
1.
按流的方向分为:输入流和输出流
2.
按流的数据单位不同分为:字节流和字符流
3.
按流的功能不同分为:节点流和处理流
二、
IO
流的四大抽象类:
字符流:
Reader Writer ......
这个问题在于 在Frame中添加组件时,每个组件先设定了位置,但是添加到Frame中后始终会出现问题。
例如:
class MyGame extends Frame
{
MyGame()
{
Label c[] = new Label[8];
for(i = 0; i<8; i++)
{
c[i] = new Lab ......