import java.io.*;
public class ReadAndWrite {
public static void main(String[] args) throws IOException {
FileOutputStream fos=new FileOutputStream("d:\\b.txt");
BufferedOutputStream bos=new BufferedOutputStream(fos);
DataOutputStream dos=new DataOutputStream(bos);
dos.writeInt(1);
dos.writeLong(2);
dos.writeChar('a');
dos.writeUTF("abc");
fos.close();
bos.close();
dos.close();
System.out.println("=======文件写入完成========");
FileInputStream fis=new FileInputStream("d:\\a.txt");
BufferedInputStream bis=new BufferedInputStream(fis);
DataInputStream dis=new DataInputStream(bis);
System.out.println(dis.readInt());
System.out.println(dis.readLong());
System.out.println(dis.readChar());
System.out.println(dis.readUTF());
fis.close();
bis.close();
dis.close();
}
} |