使用BufferedOutputStream通过while循环将字节写入文件.需要帮助 [英] Using BufferedOutputStream to write bytes to file with while loop. Help needed
本文介绍了使用BufferedOutputStream通过while循环将字节写入文件.需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用BufferedOutputStream将字节写入文件,但需要在while循环中工作.这意味着可以与TFTP服务器一起使用.它写入绝对没有任何内容的文件(这毫无意义).有人可以帮我吗?
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.
这篇关于使用BufferedOutputStream通过while循环将字节写入文件.需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文