writeBytes(str) vs write(str) in DataOutputStream

后端 未结 2 1031
死守一世寂寞
死守一世寂寞 2021-01-24 09:01

What\'s the difference between writeBytes(str) vs write(str) in DataOutputStream? And is there any Tips/Tricks to use them? Thanks in adva

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-24 09:37

    In DataOutputStream, in reference to the oracle documentation (http://docs.oracle.com/javase/7/docs/api/java/io/DataOutputStream.html) there isn't any method named write(String) but only write(byte[]), write(byte[] b, int off, int len) and write(int b). So, if you have a String, the simplest method you can use is writeBytes(String).

    There is no difference between those methods, only use the proper one according to your needs (the type of the object your data are stored in).

提交回复
热议问题