这应该很容易,但我现在无法理解它。我想通过套接字发送一些字节,像Java:从二进制文件读取,通过套接字发送字节
Socket s = new Socket("localhost", TCP_SERVER_PORT);
DataInputStream is = new DataInputStream(new BufferedInputStream(s.getInputStream()));
DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(s.getOutputStream()));
for (int j=0; j<40; j++) {
dos.writeByte(0);
}
这工作,但现在我不想writeByte到的OutputStream,而是从二进制文件读取,然后写出来。我知道(?)我需要一个FileInputStream来读取,我无法弄清楚构建整个事情。
有人可以帮我吗?
http://docs.oracle.com/javase/6/docs/api/java/io/FileInputStream.html介绍了如何从创建的FileInputStream一个文件名。 – dhblah