`
daweiyuan
  • 浏览: 20175 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

J2Me学习DataOutput

阅读更多
Use is subject to License Terms. Your use of this web site or any of its contents or software indicates your agreement to be bound by these License Terms.

Copyright © 2006 Sun Microsystems, Inc. and Motorola, Inc. All rights reserved.
Overview  Package  Class  Use  Tree  Deprecated  Index  Help
MID Profile
PREV CLASS   NEXT CLASS FRAMES    NO FRAMES   
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD
java.io
Interface DataOutput

All Known Subinterfaces:
    Datagram

All Known Implementing Classes:
    DataOutputStream

public interface DataOutput

The DataOutput interface provides for converting data from any of the Java primitive types to a series of bytes and writing these bytes to a binary stream. There is also a facility for converting a String into Java modified UTF-8 format and writing the resulting series of bytes.

For all the methods in this interface that write bytes, it is generally true that if a byte cannot be written for any reason, an IOException is thrown.

Since:
    JDK1.0, CLDC 1.0
See Also:
    DataInput, DataOutputStream

Method Summary
void write(byte[] b)
          Writes to the output stream all the bytes in array b.
void write(byte[] b, int off, int len)
          Writes len bytes from array b, in order, to the output stream.
void write(int b)
          Writes to the output stream the eight low-order bits of the argument b.
void writeBoolean(boolean v)
          Writes a boolean value to this output stream.
void writeByte(int v)
          Writes to the output stream the eight low- order bits of the argument v.
void writeChar(int v)
          Writes a char value, which is comprised of two bytes, to the output stream.
void writeChars(String s)
          Writes every character in the string s, to the output stream, in order, two bytes per character.
void writeDouble(double v)
          Writes a double value, which is comprised of eight bytes, to the output stream.
void writeFloat(float v)
          Writes a float value, which is comprised of four bytes, to the output stream.
void writeInt(int v)
          Writes an int value, which is comprised of four bytes, to the output stream.
void writeLong(long v)
          Writes an long value, which is comprised of four bytes, to the output stream.
void writeShort(int v)
          Writes two bytes to the output stream to represent the value of the argument.
void writeUTF(String s)
          Writes two bytes of length information to the output stream, followed by the Java modified UTF representation of every character in the string s.


Method Detail
write

public void write(int b)
           throws IOException

    Writes to the output stream the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

    Parameters:
        b - the byte to be written.
    Throws:
        IOException - if an I/O error occurs.

write

public void write(byte[] b)
           throws IOException

    Writes to the output stream all the bytes in array b. If b is null, a NullPointerException is thrown. If b.length is zero, then no bytes are written. Otherwise, the byte b[0] is written first, then b[1], and so on; the last byte written is b[b.length-1].

    Parameters:
        b - the data.
    Throws:
        IOException - if an I/O error occurs.

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException

    Writes len bytes from array b, in order, to the output stream. If b is null, a NullPointerException is thrown. If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown. If len is zero, then no bytes are written. Otherwise, the byte b[off] is written first, then b[off+1], and so on; the last byte written is b[off+len-1].

    Parameters:
        b - the data.
        off - the start offset in the data.
        len - the number of bytes to write.
    Throws:
        IOException - if an I/O error occurs.

writeBoolean

public void writeBoolean(boolean v)
                  throws IOException

    Writes a boolean value to this output stream. If the argument v is true, the value (byte)1 is written; if v is false, the value (byte)0 is written. The byte written by this method may be read by the readBoolean method of interface DataInput, which will then return a boolean equal to v.

    Parameters:
        v - the boolean to be written.
    Throws:
        IOException - if an I/O error occurs.

writeByte

public void writeByte(int v)
               throws IOException

    Writes to the output stream the eight low- order bits of the argument v. The 24 high-order bits of v are ignored. (This means that writeByte does exactly the same thing as write for an integer argument.) The byte written by this method may be read by the readByte method of interface DataInput, which will then return a byte equal to (byte)v.

    Parameters:
        v - the byte value to be written.
    Throws:
        IOException - if an I/O error occurs.

writeShort

public void writeShort(int v)
                throws IOException

    Writes two bytes to the output stream to represent the value of the argument. The byte values to be written, in the order shown, are:


     (byte)(0xff & (v >>)
     (byte)(0xff & v)
     

    The bytes written by this method may be read by the readShort method of interface DataInput, which will then return a short equal to (short)v.

    Parameters:
        v - the short value to be written.
    Throws:
        IOException - if an I/O error occurs.

writeChar

public void writeChar(int v)
               throws IOException

    Writes a char value, which is comprised of two bytes, to the output stream. The byte values to be written, in the order shown, are:


     (byte)(0xff & (v >>)
     (byte)(0xff & v)
    

    The bytes written by this method may be read by the readChar method of interface DataInput, which will then return a char equal to (char)v.

    Parameters:
        v - the char value to be written.
    Throws:
        IOException - if an I/O error occurs.

writeInt

public void writeInt(int v)
              throws IOException

    Writes an int value, which is comprised of four bytes, to the output stream. The byte values to be written, in the order shown, are:


     (byte)(0xff & (v >> 24))
     (byte)(0xff & (v >> 16))
     (byte)(0xff & (v >>   )
     (byte)(0xff & v)
    

    The bytes written by this method may be read by the readInt method of interface DataInput, which will then return an int equal to v.

    Parameters:
        v - the int value to be written.
    Throws:
        IOException - if an I/O error occurs.

writeLong

public void writeLong(long v)
               throws IOException

    Writes an long value, which is comprised of four bytes, to the output stream. The byte values to be written, in the order shown, are:


     (byte)(0xff & (v >> 56))
     (byte)(0xff & (v >> 48))
     (byte)(0xff & (v >> 40))
     (byte)(0xff & (v >> 32))
     (byte)(0xff & (v >> 24))
     (byte)(0xff & (v >> 16))
     (byte)(0xff & (v >> )
     (byte)(0xff & v)
    

    The bytes written by this method may be read by the readLong method of interface DataInput, which will then return a long equal to v.

    Parameters:
        v - the long value to be written.
    Throws:
        IOException - if an I/O error occurs.

writeFloat

public void writeFloat(float v)
                throws IOException

    Writes a float value, which is comprised of four bytes, to the output stream. It does this as if it first converts this float value to an int in exactly the manner of the Float.floatToIntBits method and then writes the int value in exactly the manner of the writeInt method. The bytes written by this method may be read by the readFloat method of interface DataInput, which will then return a float equal to v.

    Parameters:
        v - the float value to be written.
    Throws:
        IOException - if an I/O error occurs.
    Since:
        CLDC 1.1

writeDouble

public void writeDouble(double v)
                 throws IOException

    Writes a double value, which is comprised of eight bytes, to the output stream. It does this as if it first converts this double value to a long in exactly the manner of the Double.doubleToLongBits method and then writes the long value in exactly the manner of the writeLong method. The bytes written by this method may be read by the readDouble method of interface DataInput, which will then return a double equal to v.

    Parameters:
        v - the double value to be written.
    Throws:
        IOException - if an I/O error occurs.
    Since:
        CLDC 1.1

writeChars

public void writeChars(String s)
                throws IOException

    Writes every character in the string s, to the output stream, in order, two bytes per character. If s is null, a NullPointerException is thrown. If s.length is zero, then no characters are written. Otherwise, the character s[0] is written first, then s[1], and so on; the last character written is s[s.length-1]. For each character, two bytes are actually written, high-order byte first, in exactly the manner of the writeChar method.

    Parameters:
        s - the string value to be written.
    Throws:
        IOException - if an I/O error occurs.

writeUTF

public void writeUTF(String s)
              throws IOException

    Writes two bytes of length information to the output stream, followed by the Java modified UTF representation of every character in the string s. If s is null, a NullPointerException is thrown. Each character in the string s is converted to a group of one, two, or three bytes, depending on the value of the character.

    If a character c is in the range \u0001 through \u007f, it is represented by one byte:

    (byte)c

    If a character c is \u0000 or is in the range \u0080 through \u07ff, then it is represented by two bytes, to be written in the order shown:


     (byte)(0xc0 | (0x1f & (c >> 6)))
     (byte)(0x80 | (0x3f & c))
     

    If a character c is in the range \u0800 through uffff, then it is represented by three bytes, to be written in the order shown:


     (byte)(0xe0 | (0x0f & (c >> 12)))
     (byte)(0x80 | (0x3f & (c >>  6)))
     (byte)(0x80 | (0x3f & c))
     

    First, the total number of bytes needed to represent all the characters of s is calculated. If this number is larger than 65535, then a UTFDataFormatError is thrown. Otherwise, this length is written to the output stream in exactly the manner of the writeShort method; after this, the one-, two-, or three-byte representation of each character in the string s is written.

    The bytes written by this method may be read by the readUTF method of interface DataInput, which will then return a String equal to s.

    Parameters:
        s - the string value to be written.
    Throws:
        IOException - if an I/O error occurs.

Overview  Package  Class  Use  Tree  Deprecated  Index  Help
MID Profile
PREV CLASS   NEXT CLASS FRAMES    NO FRAMES   
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD
Copyright © 2006 Sun Microsystems, Inc. and Motorola, Inc. All rights reserved. Use is subject to License Terms. Your use of this web site or any of its content or software indicates your agreement to be bound by these License Terms.

For more information, please consult the JSR 118 specification.
分享到:
评论

相关推荐

    J2ME学习笔记 入门 学习经验

    j2me学习笔记【1】——helloworld程序示例 j2me学习笔记【2】——利用Display类的isColor()方法获取设备是否支持彩色的信息 j2me学习笔记【3】——简单的在线帮助示例 j2me学习笔记【4】——Item类的学习 j2me学习...

    非常好的关于j2me学习概要

    ### 非常好的关于J2ME学习概要 #### J2ME简介与学习路径 J2ME(Java 2 Platform, Micro Edition)是Sun Microsystems为嵌入式设备和移动设备设计的一种Java平台版本。本文章旨在为初学者提供一份详尽的J2ME学习...

    J2ME学习资料打包下载

    本压缩包包含了丰富的J2ME学习资源,包括游戏开发和中文教程,对于想要入门或提升J2ME编程技能的开发者来说极具价值。 "j2me游戏开发.rar":这个文件很可能是一个关于J2ME游戏开发的教程或实例集合。J2ME的游戏开发...

    j2me学习大全

    J2ME的学习是深入理解Java技术栈的关键一环,尤其对于想要从事移动应用开发的程序员来说至关重要。 在J2ME的学习过程中,首先要了解的是其架构。J2ME由配置(Configurations)和 profiles(Profiles)组成。配置...

    j2me学习实例

    **J2ME学习实例** J2ME,全称Java 2 Micro Edition,是Java平台的一个子集,专门设计用于资源有限的嵌入式设备和移动设备,如手机、智能手表和数字电视等。J2ME提供了开发和部署跨平台应用程序的能力,让开发者能够...

    J2ME 入门学习书籍打包下载

    本压缩包提供了两本关于J2ME入门学习的电子书籍:《J2ME基础学习教程》和《j2mejiaocheng》。以下是对这两本书籍中可能包含的知识点的详细说明: 1. **J2ME架构**: - KVM(K Virtual Machine):J2ME的虚拟机,...

    J2me学习方法总结

    ### J2ME学习方法总结 #### 一、基础练习的重要性 在学习J2ME的过程中,很多初学者可能会遇到不知道从何下手的问题。本篇文章强调了基础练习的重要性,并给出了具体的建议。作者提到,初学者不应该急于求成,一...

    J2ME学习之环境搭建

    在本文中,我们将深入探讨如何搭建J2ME(Java Micro Edition)的学习环境,特别是使用Eclipse集成开发环境(IDE)和EclipseME插件。J2ME是Java平台的一个子集,专门用于嵌入式设备和移动设备的开发,如手机、智能...

    J2ME 学习资源包02

    **J2ME 学习资源包02** 这个学习资源包是专为对Java Micro Edition(J2ME)感兴趣的开发者准备的,包含了丰富的材料,帮助深入理解和掌握移动设备上的Java应用开发。J2ME是一种轻量级的Java平台,主要用于嵌入式...

    J2ME学习环境安装文档

    ### J2ME学习环境安装知识点详解 #### 一、前言 J2ME(Java 2 Platform, Micro Edition)是Sun Microsystems为嵌入式设备和移动设备提供的Java平台。为了进行J2ME程序的开发,需要搭建一套完整的开发环境。本文档...

    J2ME 学习资源包03

    **J2ME学习资源包03** 本资源包主要涵盖了J2ME(Java 2 Micro Edition)的学习资料,包括电子书、讲座和教程,旨在帮助开发者深入理解和掌握移动设备上的Java应用程序开发。J2ME是一种Java平台,专门设计用于资源...

    4 份j2me资料,据我学习j2me经验,总结一些必读的书.

    这里提到的四份J2ME资料,是基于作者的学习经验筛选出的必读书籍,旨在帮助读者深入理解J2ME技术并提升开发能力。 1. **J2ME8.pdf** 这本书可能是关于J2ME的第八版,通常书籍的更新会涵盖最新的技术发展和最佳实践...

    J2ME学习笔记(2009年度)

    **J2ME学习笔记概述** 本《J2ME学习笔记》是2009年度的一份详尽教程,旨在帮助初学者快速入门J2ME(Java Micro Edition)开发。这份笔记精心编排,以深入浅出的方式讲解了J2ME的基础知识和核心概念,为学习者提供了...

    J2ME学习经典质料

    J2ME,全称Java 2 Micro Edition,是Java平台的一...这份"J2ME学习经典质料"压缩包很可能是包含了一些示例代码和教程,对于初学者来说是极好的学习资源。你可以通过研究这些代码来更好地理解J2ME的工作原理和编程技巧。

    J2ME开发学习资料大全

    秉着共享原则,我把收集到得这些学习资料,发出来给有兴趣的朋友,能坚持学习的朋友。 我之所以会收取一分的资源分,是想告诉大家,知识无价,如果你有幸得到学一些东西的机会,请珍惜,坚持,不要放弃。 Kevin

    Java J2ME学习实例源码集.rar

    这个压缩包"Java J2ME学习实例源码集.rar"显然是一份针对J2ME初学者的资源集合,包含了一些关于文本处理和图像处理的源代码示例。下面,我们将深入探讨这两个领域的关键知识点。 1. **文本处理**: - **文本输入与...

    J2me 基础学习 rpg游戏开发学习

    对于想要学习如何使用 J2ME 开发 RPG 游戏的初学者来说,以下是一些关键知识点: 1. **J2ME 架构**:理解 J2ME 的架构至关重要,它包括配置(Configurations)和Profile(Profiles)。配置定义了运行环境的基本硬件...

    J2ME从基础到精通详细学习课件

    J2ME从基础到精通的学习,涵盖了广泛的理论和实践知识,下面将深入解析其中的关键点。 1. **J2ME架构** J2ME由配置(Configurations)和框架(Profiles)组成。配置定义了设备的基本硬件和软件能力,如Connected ...

    J2ME 学习范例源代码

    **在“J2ME学习范例源代码”中,我们可以看到一系列针对J2ME应用程序开发的实际示例。以下是一些关键的知识点:** 1. **登录功能**:在移动设备上实现用户登录通常涉及到用户界面(UI)设计,如使用MIDlet(J2ME...

Global site tag (gtag.js) - Google Analytics