我试图将字节写入有缓冲输出的文本文件, 但我需要它来工作。 这意味着要与 TFTP 服务器一起工作。 它在文件中毫无内容地写入文件( 这毫无意义 ) 。 有人能帮我吗?
WRQ WRQ = new WRQ();
ACK ACK = new ACK();
DatagramPacket outPacket;
BufferedOutputStream bufferedOutput = new BufferedOutputStream(new FileOutputStream(filename));
byte[] bytes;
byte[] fileOut;
outPacket = WRQ.firstPacket(packet);
socket.send(outPacket);
socket.receive(packet);
while (packet.getLength() == 516){
bytes = WRQ.doWRQ(packet);
bufferedOutput.write(bytes);
outPacket = ACK.doACK(packet);
socket.send(outPacket);
socket.receive(packet);
}
bytes = WRQ.doWRQ(packet);
bufferedOutput.write(bytes);
outPacket = ACK.doACK(packet);
socket.send(outPacket);