我目前正在做一个 Objective-C 中的项目。
我需要使用 Java 类 DataOutputStream
的函数,例如 writeChars
、writeLong
、flush
和一些函数ByteArrayOutputStream
类。
具体来说,我可以在 Objective C 中使用什么,它具有与 DataOutputStream
和 ByteArrayOutputStream
类相同的功能?
这是我需要转换成 Objective C 的代码。
public static byte[] getByteArray(String key, long counter) throws IOException
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
if (key != null)
{
dos.writeChars(key);
}
dos.writeLong(counter);
dos.flush();
byte[] data = bos.toByteArray();
return data;
}
最佳答案
NSLog();
上述方法将字符串和对象作为参数。 作为,
NSLog(@"嗨,这是字符串打印的演示。");
NSLog(@"Hi this is integer %d",intValue);//这就像 printf 是不是?
编辑:
要么是 %b,要么将它转换成 NSData 对象,然后使用 %@ 打印。 Obj-c 使用 %@ 表示所有类型的对象。
unsigned int a = 0x000000FF;
NSLog(@"%x", a);//prints the most significant digits first
关于java - 相当于Objective C中Java的DataOutputStream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13742150/