求对象序列化后传输的数据大小,以字节或者KB来表示

wjs2338 2010-07-12 09:04:54
JAVA中有这种函数可以来计算序列化后对象的实际大小么(以KB或者字节计算),
还是要用外部辅助工具来截数据包~
...全文
240 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
龙四 2010-07-12
  • 打赏
  • 举报
回复
ByteArrauOutputStream中有toByteArray方法
closewbq 2010-07-12
  • 打赏
  • 举报
回复
//一个实现序列化接口的对象MM
MM m=new MM();

ObjectOutputStream out=new ObjectOutputStream(new FileOutputStream("xxxx.file"));
out.writeObject(xx);
out.close();

File f = new File("xxxx.file");
if (f.exists()) {
FileInputStream fis = null;
try {
fis = new FileInputStream(f);
} catch (FileNotFoundException e) {
e.printStackTrace();
}

try {
System.out.println("File has " + (double)((double)fis.available()/1000)
+ "KB");
} catch (IOException e) {
e.printStackTrace();
}
dracularking 2010-07-12
  • 打赏
  • 举报
回复
是通过ObjectIn(Out)putStream来传输,知道大小不难吧

62,635

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧