Java I/O常用流示例
package io;
import java.io.*;
/**
* @author 高枕吴忧
* 利用缓冲区原理,BufferedInputStream,
* 实现的文件字节流读取功能示范
*
*/
public class BufferedInOutputStream {
public BufferedInOutputStream() {
ioTest2();
}
public void ioTest2() {
FileInputStream in = null ;
BufferedInputStream bi = null;
int i= 0;
int count=0;
try{
in = new FileInputStream("D:/j/o/java2.txt");
bi = new BufferedInputStream(in);
while(( i=bi.read())!=-1) {
System.out.print((char)i);
count++;
}
System.out.println(count);
in.close();
bi.close();
}catch (IOException e){
e.printStackTrace();
}
}
public static void main(String[] args) {
new BufferedInOutputStream();
}
}
----------------------------------
package io;
import java.io.*;
/**
* @author Owner 利用缓冲区原理,BufferedInputStream,
* 实现的文件字符流读取和写入功能示范
*/
public class BufferedReaderWriter {
public BufferedReaderWriter() {
bufferRdWter();
}
public void bufferRdWter() {
FileReader fr = null;
FileWriter wt = null;
BufferedReader br = null;
BufferedWriter bw = null;
String s = "";
try {
fr = new FileReader("D:/j/o/java.txt");
br = new BufferedReader(fr);
wt = new FileWriter("D:/j/o/javat2.txt");
bw = new BufferedWriter(wt);
while ((s = br.readLine()) != null) {
bw.write(s);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
bw.flush();
wt.close();
bw.close();
br.close();
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
new BufferedReaderWriter();
}
}
--------------------------------
package io;
import java.io.*;
/**
* @author 高枕吴忧
* 数据流,注意的是先进先出.数据流方便我们用IO输出基本数据类型的值.比如它提供的readDouble();
*
*/
public class DataInOutputStr
相关文档:
构造方法摘要
Object()
方法摘要
protected Object clone()
创建并返回此对象的一个副本。
boolean equals(Object obj)
&n ......
定时器类Timer在java.util包中。使用时,先实例化,然后使用实例的schedule(TimerTask task, long delay)方法,设定指定的任务task在指定的延迟delay后执行。定时器任务类TimerTask是抽象类,继承并重写其run()方法,可实现具体任务。
schedule(TimerTask task, Date time)设定指定任务task在指定时间time执行。
cancel() ......
今天看到一道题目,是这样的:(我在里面打印了一些语句,先注释掉了)
class Singleton {
private static Singleton obj= new Singleton();
public static int counter1;
public static int counter2 = 2;
private Singleton() {
counter1++;
counter2++;
// System.out.println("Singleton counter1:" ......