I'm trying to write bytes to a file with a BufferedOutputStream but I need this to work in a while loop. This is mean to work with a TFTP server. It writes the file with absolutely nothing in it (which is pointless). Can anyone help me with this?
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);
You're not closing the stream when you're done with it.