, 通过URL  如何获取网络资源中的文件名  文件大小???

解决方案 »

  1.   

    文件大小:
    URL url1 = new URL(this.url);
              HttpURLConnection connection =(HttpURLConnection)url1.openConnection();
              connection.connect();          if (connection.getResponseCode() / 100 != 2) {
                error();
              }          int contentLength = connection.getContentLength();文件名:JTextField urljtf = new JTextField();
      JTextField filenamejtf = new JTextField();
    JPanel panel = new JPanel(); panel.add(this.filenamejtf);
     this.filenamejtf.addKeyListener(this);  public void keyReleased(KeyEvent e) {
        if (e.getSource() == this.urljtf) {
          char c = e.getKeyChar();
          if (c == '\n') {
            addTask();
          }
          else {
            String fileName = this.urljtf.getText();
            this.filename = fileName.substring(fileName.lastIndexOf('/') + 1);
            if (this.filename.equals(""))
              this.filenamejtf.setText("index.htm");
            else
              this.filenamejtf.setText(this.filename);
          }
        }
        else if (e.getSource() == this.filenamejtf) {
          char c = e.getKeyChar();
          if (c == '\n')
            addTask();
        }
      }