我的程序好像有问题,帮我看看????
这个程序在编译和运行都没有问题,我的“nihao.txt”这个文件的路径是在:e:\nihao.txt但当我在文本框输入:http://127.0.0.1/nihao.txt 时,
就出现下面错误信息:
Connection reset
at (Unknown Source)
at (Unknown Source)
at (Unknown Source)
at (Unknown Source)
at (Unknown Source)
at (Unknown Source)
at (Unknown Source)
at (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.(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.(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.(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 *;
import *;
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);
}
}