DateInputStream & DateOutputStream
package com.company01.IO;
import java.io.DataOutputStream;
import java.io.FileOutputStream;
public class DataOutputStreamTest01 {
public static void main(String[] args) throws Exception{
DataOutputStream dos = new DataOutputStream(new FileOutputStream("test01.txt"));
byte b = 10;
short s = 11;
int i = 12;
long l = 1000L;
float f = 2.1f;
double d = 3.2;
boolean flag = false;
char c = 'a';
dos.writeByte(10);
dos.writeShort(s);
dos.writeInt(i);
dos.writeLong(l);
dos.writeFloat(f);
dos.writeDouble(d);
dos.writeBoolean(flag);
dos.writeChar(c);
dos.flush();
dos.close();
}
}
package com.company01.IO;
import java.io.*;
public class DataInputStreamTest01 {
public static void main(String[] args) throws Exception{
DataInputStream dis = new DataInputStream(new FileInputStream("test01.txt"));
byte b = dis.readByte();
short s = dis.readShort();
int i = dis.readInt();
long l = dis.readLong();
float f = dis.readFloat();
double d = dis.readDouble();
boolean flag = dis.readBoolean();
char c = dis.readChar();
System.out.println(b);
System.out.println(s);
System.out.println(i);
System.out.println(l);
System.out.println(f);
System.out.println(d);
System.out.println(flag);
System.out.println(c);
dis.close();
}
}
PrintStream & PrintWriter
package com.company01.IO;
import javax.xml.crypto.Data;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
public class PrintStreamTest01 {
public static void main(String[] args) throws Exception{
System.out.println("HelloWorld");
PrintStream ps = System.out;
ps.println("Java.....");
System.setOut(new PrintStream(new FileOutputStream("log", true)));
System.out.println("qwer");
SimpleDateFormat sdf = new SimpleDateFormat("yyy-MM-dd HH:mm:ss SSS");
System.out.println("m1方法开始执行的时间:" + sdf.format(new Date()));
m1();
System.out.println("m1方法执行后的时间:" + sdf.format(new Date()));
}
public static void m1(){
System.out.println("m1 method executed!");
}
}