1

このコードで保存された でString読み取る方法:DataInputStream

DataOutputStream dataOut = new DataOutputStream (out); // Some other stream
String title = processed.getTitle();
dataOut.writeInt(title.length());
dataOut.writeBytes(title);
4

3 に答える 3

1

ByteArrayOutputStreamandByteArrayInputStreamと byte 配列を中間バッファーとして使用できます。

ByteArrayOutputStream out = new ByteArrayOutputStream();

// Some other streams
DataOutputStream dataOut = new DataOutputStream (out); 
String title = processed.getTitle();
dataOut.writeInt(title.length());
dataOut.writeBytes(title);

ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
DataInputStream dataIn = new DataInputStream(in);
于 2013-10-24T11:34:49.043 に答える
-1
dataOut.writeUTF(title);
// ...
String title = dataIn.readUTF();

... この形式で記述した場合、タイトルが 65533 バイトを超える必要がない場合: Javadoc を参照してください。

于 2013-10-30T23:50:08.830 に答える