String strMapdef = "http://10.238.29.42:8080/webgis/map/新疆.mdf";
      URL u = new URL(strMapdef);
      URLConnection conn = u.openConnection();
      isRemoteFile = conn.getInputStream();10.238.29.42是个Tomcat服务器,以下代码在Applet中运行,会报错:
java.io.FileNotFoundException: http://10.238.29.42:8080/webgis/map/新疆.mdf at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source) at sun.plugin.net.protocol.http.HttpURLConnection.getInputStream(Unknown Source) at business.knowledgebase.map.MapApplet.loadMapdefine(MapApplet.java:326) at business.knowledgebase.map.MapApplet.start(MapApplet.java:118) at sun.applet.AppletPanel.run(Unknown Source) at java.lang.Thread.run(Unknown Source)事实上,那个文件是存在的。为什么?

解决方案 »

  1.   

    String strMapdef = "http://10.238.29.42:8080/webgis/map/新疆.mdf";
          URL u = new URL(strMapdef);
          URLConnection conn = u.openConnection();
          isRemoteFile = conn.getInputStream();----------------------------------------------------------------------
    URLConnection.url
    The URL represents the remote object on the World Wide Web to which this connection is opened. 
    The value of this field can be accessed by the getURL method. The default value of this variable is the value of the URL argument in the URLConnection constructor.
    ----------------------------------
    public final class URL 
    extends Object 
    implements Serializable 
    Class URL represents a Uniform Resource Locator, a pointer to a "resource" on the World Wide Web. A resource can be something as simple as a file or a directory, or it can be a reference to a more complicated object, such as a query to a database or to a search engine. More information on the types of URLs and their formats can be found at: http://www.ncsa.uiuc.edu/demoweb/url-primer.html 
    In general, a URL can be broken into several parts. The previous example of a URL indicates that the protocol to use is http (HyperText Transport Protocol) and that the information resides on a host machine named www.ncsa.uiuc.edu. The information on that host machine is named demoweb/url-primer.html. The exact meaning of this name on the host machine is both protocol dependent and host dependent. The information normally resides in a file, but it could be generated on the fly. This component of the URL is called the file component, even though the information is not necessarily in a file. A URL can optionally specify a "port", which is the port number to which the TCP connection is made on the remote host machine. If the port is not specified, the default port for the protocol is used instead. For example, the default port for http is 80. An alternative port could be specified as: http://www.ncsa.uiuc.edu:8080/demoweb/url-primer.html 
    A URL may have appended to it an "anchor", also known as a "ref" or a "reference". The anchor is indicated by the sharp sign character "#" followed by more characters. For example, http://java.sun.com/index.html#chapter1 
    This anchor is not technically part of the URL. Rather, it indicates that after the specified resource is retrieved, the application is specifically interested in that part of the document that has the tag chapter1 attached to it. The meaning of a tag is resource specific. An application can also specify a "relative URL", which contains only enough information to reach the resource relative to another URL. Relative URLs are frequently used within HTML pages. For example, if the contents of the URL: http://java.sun.com/index.html 
    contained within it the relative URL: 
    FAQ.html 
    it would be a shorthand for: 
    http://java.sun.com/FAQ.html 
    The relative URL need not specify all the components of a URL. If the protocol, host name, or port number is missing, the value is inherited from the fully specified URL. The file component must be specified. The optional anchor is not inherited. 
      

  2.   

    如果是英文的文件名,是可以的.现在是中文文件名,通过HTTP方式取得数据流有问题的.
      

  3.   

    把第一句改成:String strMapdef = java.net.URLEncoder.encode("http://10.238.29.42:8080/webgis/map/新疆.mdf");这样就可以了!
      

  4.   

    不行,会提示:
    java.net.MalformedURLException: no protocol: http%3A%2F%2F10.238.29.43%3A8001%2Fmaplexu%2Fknowledgebase%2Fmapinfo%2F%D0%C2%BD%AE.mdf
    at java.net.URL.(URL.java:537)
    at java.net.URL.(URL.java:434)
    at java.net.URL.(URL.java:383)
      

  5.   

    另把主机头也进行encode啊String strMapdef = "http://10.238.29.42:8080/" + java.net.URLEncoder.encode("webgis/map/新疆.mdf");
      

  6.   

    String strMapdef = "http://10.238.29.42:8080/webgis/map/" + java.net.URLEncoder.encode("新疆")+".mdf";