DataInputStream 的skipBytes 和skip 之间的区别?
我现在想知道,这两种方法有什么区别:
DataInputStream.skipBytes
和 DataInputStream.skip
。
我知道 skip
必须来自 InputStream
和 skipBytes
来自 DataInput
,但仍然存在任何差异。您知道,在 J2ME 中使用流时,事情会变得非常棘手,所以我需要知道!
从 JSR-75 中的 FileConnection 返回的输入/数据输入流在处理上与任何其他此类流有什么不同吗?
谢谢!
I wonder now, what is the difference between the two methods:
DataInputStream.skipBytes
and DataInputStream.skip
.
I am aware of the fact that skip
must come from InputStream
and skipBytes
from DataInput
, but still, is there any difference. You know, when using streams in J2ME, things get pretty tricky so I need to know!
Would the Input/DataInput Streams returned from the FileConnection
in JSR-75 be any different in handling than any other such streams?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
此外,skip() 采用 long 作为参数,因此您可以一次跳过更多字节。对于大文件很有用
Also, skip() takes a long as an argument, so you can skip over many more bytes at a time. Useful for large files
来自
DataInputStream
:正如您从代码中看到的,
skipBytes
使用skip (InputStream.skip)
我唯一能说的是,如果包装的inputStream(DataInputStream内的InputStream)中的数据被另一个线程更改,那么skipBytes和skip的结果可能会不同。但如果您的应用程序仅使用单线程,那么skipBytes 和skip 是相同的。
from
DataInputStream
:as you can see from the code,
skipBytes
usesskip (InputStream.skip)
the only thing that i can say is that if data in your wrapped inputStream (InputStream inside DataInputStream)changes by another thread, then the result of skipBytes and skip may be different. but if your application just working with single thread then skipBytes and skip are the same.
如果您尝试使用.skip()返回而不是前进。您会注意到它将成功以字节为单位返回。但是,如果您尝试使用 skipBytes() 以字节为单位返回,假设您想向后移动 10 个字节 dis.skipBytes(n),它将不起作用,它将保持不变。因此,总而言之,这是 skip 和 skipBytes 之间的主要区别。另一个区别是,skip(long i)、skipBytes(int i)、skip 采用long 类型,这使您能够跳过更大的文件需要更多的字节。
If you try to use .skip() to return back instead of moving forward. You will notice that it will successfully get back in bytes. However, if you try to go back in bytes using skipBytes(), let's say you want to move 10 bytes back dis.skipBytes(n), it won't work, it will stay the same. So, in conclusion this is the main difference between skip and skipBytes. Another difference is that, skip(long i), skipBytes(int i), skip takes a long type which gives you the ability to skip more bytes for larger files.