首页 > 编程语言 > 详细

【转】JAVA 读写二进制文件

时间:2015-09-24 12:40:31      阅读:178      评论:0      收藏:0      [点我收藏+]

原文网址:http://shiminghua234.blog.163.com/blog/static/263912422011619102350866

import java.io.*; 
/** 
* Java读取解析二进制数据 

* @author leizhimin 2008-10-14 12:42:51 
*/ 
public class TestLicenses { 
        public static void main(String[] args) throws IOException { 
                testDataOutputStream(); 
                testDataInputStream(); 
        } 
        /** 
         * 生成二进制数据文件 
         * 
         * @throws IOException 
         */ 
        public static void testDataOutputStream() throws IOException { 
                DataOutputStream dos = new DataOutputStream(new FileOutputStream("C:\\dos.dat")); 
                dos.writeBoolean(true); 
                dos.writeByte(‘a‘); 
                dos.writeDouble(234.44); 
                dos.writeFloat(11.23f); 
                dos.writeLong(555L); 
                dos.writeInt(333); 
                dos.writeShort(23); 
                dos.writeUTF("UTFString"); 
                dos.close(); 
        } 
        /** 
         * 解析二进制数据文件 
         * 
         * @throws IOException 
         */ 
        public static void testDataInputStream() throws IOException { 
                DataInputStream dis = new DataInputStream(new FileInputStream("C:\\dos.dat")); 
                System.out.println(dis.readBoolean()); 
                System.out.println((char) dis.readByte()); 
                System.out.println(dis.readDouble()); 
                System.out.println(dis.readFloat()); 
                System.out.println(dis.readLong()); 
                System.out.println(dis.readInt()); 
                System.out.println(dis.readShort()); 
                System.out.println(dis.readUTF()); 
                dis.close(); 
        } 
}

【转】JAVA 读写二进制文件

原文:http://www.cnblogs.com/wi100sh/p/4834545.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!