代码太多就贴出一部分吧。就是毕老师视频第24天07.Tomcat服务端那节课中的代码。- private void showDir()throws Exception
- {
- ta.setText("");
- String url = tf.getText();//http://192.168.1.254:8080/myweb/demo.html
-
- int index1 = url.indexOf("//")+2;
- int index2 = url.indexOf("/",index1);
- String str = url.substring(index1,index2);
- String[] arr = str.split(":");//主要是这句,有点不太懂这句话的作用
- String host = arr[0];
- int port = Integer.parseInt(arr[1]);
- String path = url.substring(index2);
- //ta.setText(str+"...."+path);
- Socket s = new Socket(host,port);
-
-
复制代码 |
|