简单的java类下载文件 [英] Simple java class to download the file

查看:133
本文介绍了简单的java类下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用简单的java类下载一个文件,使用以下代码:

I am trying to download a file using simple java class using the following code:

public class Download {  

     public static void main(String[] args) throws Exception {  

        Download d = new Download();  
        d.URLSetUp("http://www.sheldonbrown.com/web_sample1.html");  
     }  

    public String URLSetUp(String urlProp) throws Exception {  

        StringBuffer tempData = new StringBuffer();  
        String contentXML = "";  
        String line = "";  
        URL url1;  
         try {  
            url1 = new URL(urlProp);  

            URLConnection conn = url1.openConnection();  

            conn.setDoOutput(true);  
             OutputStreamWriter wr = new OutputStreamWriter(conn
                .getOutputStream());  

             BufferedReader rd = new BufferedReader(new InputStreamReader(conn
                .getInputStream()));  
              while ((line = rd.readLine()) != null) {  
                 tempData.append(line);  
             }  
             contentXML = tempData.toString();  

            wr.close();  
            rd.close();  

         } catch (MalformedURLException e) {  

             e.printStackTrace();  
         } catch (IOException e) {  

             e.printStackTrace();  
        }  
         if (contentXML != null) {  
             return contentXML;  
        } else {  

             System.out.println("Error");  
         }  
         return null;  

     }  
}  

它给我以下错误: / p>

Its giving me following error:

#  
# An unexpected error has been detected by Java Runtime Environment:  
#  
#  Internal Error (434C41535326494C453041525345520E4350500B65), pid=5156, tid=4296  
#  
# Java VM: Java HotSpot(TM) Client VM (1.6.0_03-b05 mixed mode)  
# An error report file with more information is saved as hs_err_pid5156.log  
#  
# If you would like to submit a bug report, please visit:  
#   http://java.sun.com/webapps/bugreport/crash.jsp  
#

请让我知道,如果你有任何soultion。

Please let me know if any of you have got any soultion.

感谢

Sneha

Thanks
Sneha

推荐答案

你可能已经确定,这是你的虚拟机崩溃。在Java中通常没有任何东西可以触发它,因此我将从升级JVM开始。 1.6.0_ 03 很旧。

As you've probably determined, that's your virtual machine crashing. Nothing you do normally within Java should trigger this, and consequently I would start by upgrading your JVM. 1.6.0_03 is quite old.

此页面详细介绍了Java 7下载,以及早期的Java 6 JDK。你可以看到它们是次要版本31,所以你是相对过时的。

This page details the Java 7 downloads, and the earlier Java 6 JDKs too. As you can see they're up to minor version 31 so you're relatively out-of-date.

如果你想进一步调试,请注意上面的错误报告文件,并查看此SO答案

If you want to debug this further, note the above error report file and check out this SO answer.

这篇关于简单的java类下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆