readUTF, readUTFBytes, writeUTF, writeUTFBytes in AS3
Posted on 2007-11-02 by
仔细看看readUTF, readUTFBytes, writeUTF, writeUTFBytes发现还真不一样。
writeUTF时先写两个字节的长度信息,然后再跟具体的UTF-8编码的字节。
比如“睡觉了”是3×3=9个字节,用writeUTF后,共2+9=11个字节。
同理,readUTF时先读两个字节的长度信息,但此时的长度信息有一个用处:一个ByteArray内容同writeUTF(”睡觉了”),然后再做几次writeByte(0),最后用readUTF读取这个ByteArray依然是”睡觉了”3个字。
详细文档如下:
《flash 9.0_cn ActionScriptLangRefV3 flash.utils.ByteArray》
readUTF () 方法
public function readUTF():String
语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9
从字节流中读取一个 UTF-8 字符串。 假定字符串的前缀是无符号的短整型(以字节表示长度)。
返回 String — UTF-8 编码的字符串。
引发 EOFError — 没有足够的数据可供读取。
另请参见
flash.utils.IDataInput.readUTF()
readUTFBytes () 方法
public function readUTFBytes(length:uint):String
语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9
从字节流中读取一个由 length 参数指定的 UTF-8 字节序列,并返回一个字符串。
参数 length:uint — 指明 UTF-8 字节长度的无符号短整型数。
返回 String — 由指定长度的 UTF-8 字节组成的字符串。
引发 EOFError — 没有足够的数据可供读取。
writeUTF () 方法
public function writeUTF(value:String):void
语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9
将 UTF-8 字符串写入字节流。 先写入以字节表示的 UTF-8 字符串长度(作为 16 位整数),然后写入表示字符串字符的字节。
参数 value:String — 要写入的字符串值。
引发 RangeError — 如果长度大于 65535。
writeUTFBytes () 方法
public function writeUTFBytes(value:String):void
语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9
将 UTF-8 字符串写入字节流。 类似于 writeUTF() 方法,但 writeUTFBytes() 不使用 16 位长度的词为字符串添加前缀。
参数 value:String — 要写入的字符串值。
累了,睡了。
分享到:
相关推荐
dos.writeUTF(userName); dos.writeUTF(mobilePhone); dos.writeUTF(email); dos.writeUTF(phone); baos.close(); dos.close(); return baos.toByteArray(); } public static Account deserialize(byte[]...
以上代码利用Socket对象和ServerSocket对象进行简单的网络交互,即客户端通过DataOutputStream对象的writeUTF()方法向服务器发送消息,服务器利用DataInputStream对象的readUTF()方法读出数据。 看上去挺好,但...
前端开源库-readutfreadutf,一个围绕fs.readfile的薄包装,根据您的要求自动将编码设置为utf8
第四步,利用DataInputstream类的readUTF函数,进行数据的准备,并利用DateOutputstream类的writeUTF方法,将信息发送出去。 第五步,当传输结束后,调用socket的close方法,关闭连接。 利用Java实现一个简单的...
BufferedReader sin = new BufferedReader(new InputStreamReader(System.in)); System.out.println(""); System.out.println(""); str = din.readUTF(); System.out.println("从客户接受...
String data_MIDlet = d_Inputstream.readUTF(); d_Inputstream.close(); System.out.println( "从手机上接收过来的信息:" + data_MIDlet ); String record_String = new String( data_MIDlet + " ,成功登陆" ...
此类通过s = new Socket("127.0.0.1", 8888);...启动一个线程,由此线程来从服务器端读入数据String str = dis.readUTF();并且将数据展现在客户端taContent.setText(taContent.getText() + str + '\n');
System.out.println(dataInputStream.readUTF()); } } catch (IOException e) { e.printStackTrace(); } } } Client import java.io.DataOutputStream; import java.io.IOException; import java....
message=chessclient.in.readUTF(); acceptMessage(message); } } catch(IOException es) { } } } public class chessClient extends Frame implements ActionListener,KeyListener { userPad userpad=...
String path=new Scanner(System.in).nextLine(); File dir=new File(path); long len=dirLength(dir); System.out.println(len/1024+"KB"); } private static long dirLength(File dir) { /* * 1 ...
in=new DataInputStream(chatSocket.getInputStream()); out=new DataOutputStream(chatSocket.getOutputStream()); clientThread clientthread=new clientThread(this); clientthread.start(); isOnChat=true;...
message=chessclient.in.readUTF(); acceptMessage(message); } } catch(IOException es){ } } } public class chessClient extends Frame implements ActionListener,KeyListener{ userPad ...
标识符拆分(也称为标识符名称标记化)是将程序标识符字符串(如getInt或readUTF8stream为组件令牌的任务:[ get , int ]和[ read , utf8 , stream ]。 在各种情况下都需要分离标识符,包括应用于源代码分析和...
//读取上传过过来的文件名 String fileName = dis.readUTF(); System.out.println("服务器接收到自"+ip+"的"+fileName+"文件"); //将接收到的文件保存到指定的目录 os = new FileOutputStream("File/"+fileName); ...