ReadAndWriteData

/**
* 读取和写入不同基本类型数据 *
* @throws IOException
*/
public static void main(String[] args) throws IOException {
try{
FileOutputStream out1=new FileOutputStream("c:\\myDoc\\hello.txt");
BufferedOutputStream out2=new BufferedOutputStream(out1);
DataOutputStream out=new DataOutputStream(out2);
out.writeByte(1);
out.writeLong(2);
out.writeChar('c');
out.writeUTF("hello");
out.close();
}catch(IOException e){
System.out.println("出错:"+e);
}
System.out.println("文件写入完成。");
System.out.println("文件开始读取。。。");
try{
FileInputStream in1=new FileInputStream("c:\\myDoc\\hello.txt");
BufferedInputStream in2=new BufferedInputStream(in1);
DataInputStream in=new DataInputStream(in2);
System.out.println(in.readByte());
System.out.println(in.readLong());
System.out.println(in.readChar());
System.out.println(in.readUTF());

in.close();
}catch(IOException e){
System.out.println("出错:"+e);
}
System.out.println("文件读取完成。");

}

}

上一篇:[Linux] 大数据库导出大文件统计并去重


下一篇:使用 DLL 的优点