这个资源保存你的本地以后你就可以用file对象来控制了。

解决方案 »

  1.   

    搂主是想File myfile=new File("http://mms.tom.com/image_128x128/36095.gif")来远程调用这个文件?
    估计不行。
    还是得存储再你的项目文件夹里面才行
      

  2.   

    File支持以url建立一个对象的啊!
      

  3.   

    URL url = new URL ("http://mms.tom.com/image_128x128/36095.gif");
    InputStream is = url.openStream ();
    BufferedReader br = new BufferedReader (new InputStreamReader (is));
      

  4.   

    写一个applet
    试试 楼上的办法咋样
      

  5.   

    to zhutouzip: please show me a sample.
      

  6.   

    brucejia 正解,这个十分简单,java.net.URL类十分好用,甚至已经所代理服务器都考虑了,你只要直接如楼上那样调用就可以了,然后把内容从Reader中再写到File对象里就可以了(File可以创建一个临时文件的)
      

  7.   

    试试这样:
    URI uri = new URI("http://mms.tom.com/image_128x128/36095.gif");
    File file = new File(uri);可以吗
      

  8.   

    public static byte[] getBytesFromFile(File file) throws IOException
    {
    InputStream ins = new FileInputStream(file);
    byte[] bytes = new byte[ ins.available() ];
    ins.read(bytes);
    ins.close();
    ins = null;
    return bytes;
    }

    上面这样的方法得到一个字节数组,和我下面得到的数组,会有什么不同呢,
    URL url = new URL("http://218.204.253.99:8090/xxx/yyy/9038.jpg");
    InputStream imageInput = url.openStream();
    int ch = -1;
    StringBuffer sb = new StringBuffer();
    while((ch = imageInput.read())!= -1){
    System.out.println("ok");
    sb.append(ch);
    }byte[] bytes = sb.getBytes();有什么不同呢?
      

  9.   

    to  Mailbomb:不行的,应该是用file:位前缀的url
      

  10.   

    所以如果楼主关注的是那个“File对象”的话,应该是不行的。如果是关注的“File对象”的内容的话就方式多了,上面就已经提出不少办法了。
      

  11.   

    sb.append(ch);应该是是sb.append((char)ch);,然后 两种实现方式有什么不同能,因为最终程序运行结果不同
      

  12.   

    我关注的是最终的到的那个byte[],但在本机用file就可以,用后面url的方法,图像就显示不出来,说格式错误:(
      

  13.   

    StringBuffer append(char c) 
              Appends the string representation of the char argument to this string buffer. StringBuffer append(int i) 
              Appends the string representation of the int argument to this string buffer. 试试看(33在ASCII表中是“!”):
         sb.append(33);
         sb.append((char)33);
    结果是什么?同时你犯了一个错误StringBuffer固然比String要好。但是那2个类都不是作为数据存储的好对象!
    尤其是在io相关的时候,推荐你用byte[]或者ByteArrayOutputStream