如何将一个string类型的字符串转化成URL类型
十万火急,谢了先!

解决方案 »

  1.   

    楼上说的正确啊,不过不知道是不是你要的答案?还是你想把string转换成URL请求编码格式
    java.net.URLEncoder.encode(string, "UTF-8")
      

  2.   

    这是我的部分代码,不知道错在那里了,或者还有什么别的方法可以实现吗
        FileDialog op = new FileDialog(this,"插入",FileDialog.LOAD);
        op.setVisible(true);
        String filename = op.getDirectory()+op.getFile();//要转化的字符串 
        System.out.println("filename="+filename); 
        
        URL url=null;
        try{
             url = new URL("file",null,filename);// String转化成URL
        }
        catch(Exception e){
        
         System.out.println("e="+e); 
         }
        System.out.println("url="+url); //输出结果是file:E:\My Pictures\11.jpg
        ImageIcon bicon = new ImageIcon(url);  //到这句就出错了         
        DrawObject drawObject = new DrawIcon(bicon, 100, 100,1); 
      

  3.   

    URL
    public URL(String spec)
        throws MalformedURLException
    Creates a URL object from the String representation.
      

  4.   

    import java.net.URL;try
    {
     URL url = new URL("http://www.csdn.net");
    }
    catch(Exception e)
    {
     System.out.println("错误的网址");
    }
      

  5.   

    你这样试一试:
    File file = new File("E:\My Pictures\11.jpg");
    URL url = new URL();
    url = file.toURL();