0

通过使用实例PrintStreamprintln函数,我可以将原始字符串发送给客户端。但是,我想将整个.html文件发送给客户端以便查看网页。出于这个原因,我的方法应该是什么?我试图读取一个文件并给出 println 函数上读取的任何内容。但是,尝试失败了。

4

1 回答 1

1

可能这样的事情会有所帮助:

// sendfile
File myFile = new File ("source.html");
byte [] mybytearray  = new byte [(int)myFile.length()];
FileInputStream fis = new FileInputStream(myFile);
BufferedInputStream bis = new BufferedInputStream(fis);
bis.read(mybytearray,0,mybytearray.length);
OutputStream os = sock.getOutputStream();
System.out.println("Sending...");
os.write(mybytearray,0,mybytearray.length);
os.flush();
sock.close();
于 2013-03-25T11:02:01.133 回答