我的程序好像有问题,帮我看看????
这个程序在编译和运行都没有问题,我的“nihao.txt”这个文件的路径是在:e:\nihao.txt但当我在文本框输入:http://127.0.0.1/nihao.txt 时,
就出现下面错误信息:
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read1(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown So
urce)
at DownLoad$1.actionPerformed(DownLoad.java:54)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour
ce)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
import java.net.*;
import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class DownLoad extends JFrame
{
final JTextField JF;
JScrollPane JS;
JLabel JL1;
JTextArea JA;
JButton JB;
JPanel JP1;
JPanel JP2;
public DownLoad(String str)
{
super(str);
//建立内容面板
JP1=new JPanel();
JP2=new JPanel();
//建立组件
JF=new JTextField(30);
JL1=new JLabel("URL:");
JA=new JTextArea(30,20);
JS=new JScrollPane(JA);
JB=new JButton("下载");
//布置JP1,JP2面板
JP1.add(JL1);
JP1.add(JF);
JP2.add(JB);
//添加组件
Container c=this.getContentPane();
c.setLayout(new BorderLayout());
c.add(JS,BorderLayout.CENTER);
c.add(JP1,BorderLayout.NORTH);
c.add(JP2,BorderLayout.SOUTH);
//添加监听器
JB.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
String str=JF.getText();
System.out.println(str);
URL address=new URL(str);
URLConnection conn=address.openConnection();
InputStream in=conn.getInputStream();
InputStreamReader ISR=new InputStreamReader(in);
BufferedReader BR=new BufferedReader(ISR);
FileOutputStream FS=new FileOutputStream("1.txt");
PrintWriter FO=new PrintWriter(FS,true);
FO.println(BR.readLine());
BR.close();
FO.close();
}
catch(Exception ee)
{
ee.printStackTrace();
}
}
});
}
public static void main(String[] args)
{
DownLoad DL=new DownLoad("下载窗口");
DL.setSize(500,450);
DL.setLocation(200,150);
DL.setVisible(true);
DL.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
----------------解决方案--------------------------------------------------------
你这个好像是Java小应用程序吧,那就还应该有import Java.Applet.*而且是用html来运行的。
----------------解决方案--------------------------------------------------------