useFtpApplet.java:208: 找不到符号
符号: 类 DataOutputStrean
位置: 类 useFtpApplet
outputs=new DataOutputStrean(outs);怎么修改程序代码:
import sun.net.ftp.*;
import sun.net.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.io.*;
public class useFtpApplet extends Applet
{ //属性
FtpClient aftp;
DataOutputStream outputs;
TelnetInputStream ins;
TelnetOutputStream outs;
TextArea IsArea;
Label LblPrompt;
Button BtnConn;
Button BtnClose;
TextField TxtUID;
TextField TxtPWD;
TextField TxtHost;
int ch;
public String a="没有连接主机";
String hostname="";
//方法
/*public void init();
public boolean connect(String hostname,String uid,String pwd);
public void stop();
public boolean action(Event evt,Object obj);
public boolean sendFile(String filepathname);
public void showFileContents();
public static void main(String args[]);}*/
public void init()
{
//设置背景和布局
setBackground(Color.white);
setLayout(new GridBagLayout());
//网袋布局
GridBagConstraints GBC=new GridBagConstraints();
LblPrompt=new Label("没有连接主机");
LblPrompt.setAlignment(Label.LEFT);
//建立接钮实例
BtnConn=new Button("连接");
BtnClose=new Button("断开");
BtnClose.enable(false); //建立文本域实例
TxtUID=new TextField("",15);
TxtPWD=new TextField("",15);
TxtPWD.setEchoCharacter('*');
TxtHost=new TextField("",20); //建立标签实例
Label LblUID=new Label("User ID:");
Label LblPWD=new Label("PWD:");
Label LblHost=new Label("Host:"); //建立文本框,设置属性
IsArea=new TextArea(30,80);
IsArea.setEditable(false); GBC.gridwidth=GridBagConstraints.REMAINDER;
GBC.fill =GridBagConstraints.HORIZONTAL;
((GridBagLayout)getLayout()).setConstraints(LblPrompt,GBC);
add(LblPrompt); GBC.gridwidth=1;
((GridBagLayout)getLayout()).setConstraints(LblHost,GBC);
add(LblHost);
GBC.gridwidth=GridBagConstraints.REMAINDER;
((GridBagLayout)getLayout()).setConstraints(TxtHost,GBC);
add(TxtHost); GBC.gridwidth=1;
((GridBagLayout)getLayout()).setConstraints(LblUID,GBC);
add(LblUID);
GBC.gridwidth=1;
((GridBagLayout)getLayout()).setConstraints(TxtUID,GBC);
add(TxtUID); GBC.gridwidth=1;
((GridBagLayout)getLayout()).setConstraints(LblPWD,GBC);
add(LblPWD);
GBC.gridwidth=1;
((GridBagLayout)getLayout()).setConstraints(TxtPWD,GBC);
add(TxtPWD);
GBC.gridwidth=1;
GBC.weightx=2;
((GridBagLayout)getLayout()).setConstraints(BtnConn,GBC);
add(BtnConn);
GBC.gridwidth=GridBagConstraints.REMAINDER; ((GridBagLayout)getLayout()).setConstraints(BtnClose,GBC);
add(BtnClose); GBC.gridwidth=GridBagConstraints.REMAINDER;
GBC.fill =GridBagConstraints.HORIZONTAL;
((GridBagLayout)getLayout()).setConstraints(IsArea,GBC);
add(IsArea);}public boolean connect(String hostname,String uid,String pwd)
{
this.hostname=hostname;
LblPrompt.setText("正在连接,请等待~~~~~~");
try
{
aftp=new FtpClient(hostname);
aftp.login(uid,pwd);
aftp.binary();
showFileContents();
}
catch(FtpLoginException e)
{
a="无权限与主机:"+hostname+"连接!";
LblPrompt.setText(a);
return false;
}
catch(IOException e)
{
a="连接主机"+hostname+"失败!";
LblPrompt.setText(a);
return false;
}
catch(SecurityException e)
{
a="无权限与主机:"+hostname+"连接!";
LblPrompt.setText(a);
return false;
}
LblPrompt.setText("连接主机:"+hostname+"成功!");
return true;}public void stop()
{
try
{
aftp.closeServer();
}
catch(IOException e)
{}
}public boolean action(Event evt,Object obj)
{
if(evt.target==BtnConn)
{
LblPrompt.setText("正在连接,请等待~~~~");
if(connect(TxtHost.getText(),TxtUID.getText(),TxtPWD.getText()))
{
BtnConn.setEnabled(false);
BtnClose.setEnabled(true);
}
return true;
} if(evt.target==BtnClose)
{
stop();
BtnConn.enable(true);
BtnClose.enable(false);
LblPrompt.setText("与主机"+hostname+"连接己断开!");
return true;
} return super.action(evt,obj);}public boolean sendFile(String filepathname)
{
boolean result=true;
if(aftp!=null)
{
LblPrompt.setText("正在粘贴文件,请耐心等待~~~~~~~");
String contentperline;
try
{
a="粘贴成功!";
String fg=new String("\\");
int index=filepathname.lastIndexOf(fg);
String filename=filepathname.substring(index+1);
File localFile;
localFile=new File(filepathname);
RandomAccessFile sendFile=new RandomAccessFile(filepathname,"r");
//上载文件
sendFile.seek(0);
outs=aftp.put(filename);
outputs=new DataOutputStrean(outs);
while(sendFile.getFilePointer()<sendFile.length())
{
ch=sendFile.read();
outputs.write(ch);
}
outs.close();
sendFile.close();
}
catch(IOException e)
{
a="粘贴失败!";
result=false;
}
LblPrompt.setText(a);
showFileContents();
}
else
{
result=false;
}
return result;}
public void showFileContents()
{
StringBuffer buf=new StringBuffer();
IsArea.setText("");
try
{
ins=aftp.list();
while((ch=ins.read())>=0)
{
buf.append((char)ch);
}
IsArea.appendText(buf.toString());
ins.close();
}
catch(IOException e) {}}public static void main(String args[])
{
Frame f=new Frame("FTP Client");
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
//退出系统
System.exit(0);
} });
useFtpApplet ftp=new useFtpApplet();
ftp.init();
ftp.start();
f.add(ftp);
f.pack();
f.setVisible(true);
}}
符号: 类 DataOutputStrean
位置: 类 useFtpApplet
outputs=new DataOutputStrean(outs);怎么修改程序代码:
import sun.net.ftp.*;
import sun.net.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.io.*;
public class useFtpApplet extends Applet
{ //属性
FtpClient aftp;
DataOutputStream outputs;
TelnetInputStream ins;
TelnetOutputStream outs;
TextArea IsArea;
Label LblPrompt;
Button BtnConn;
Button BtnClose;
TextField TxtUID;
TextField TxtPWD;
TextField TxtHost;
int ch;
public String a="没有连接主机";
String hostname="";
//方法
/*public void init();
public boolean connect(String hostname,String uid,String pwd);
public void stop();
public boolean action(Event evt,Object obj);
public boolean sendFile(String filepathname);
public void showFileContents();
public static void main(String args[]);}*/
public void init()
{
//设置背景和布局
setBackground(Color.white);
setLayout(new GridBagLayout());
//网袋布局
GridBagConstraints GBC=new GridBagConstraints();
LblPrompt=new Label("没有连接主机");
LblPrompt.setAlignment(Label.LEFT);
//建立接钮实例
BtnConn=new Button("连接");
BtnClose=new Button("断开");
BtnClose.enable(false); //建立文本域实例
TxtUID=new TextField("",15);
TxtPWD=new TextField("",15);
TxtPWD.setEchoCharacter('*');
TxtHost=new TextField("",20); //建立标签实例
Label LblUID=new Label("User ID:");
Label LblPWD=new Label("PWD:");
Label LblHost=new Label("Host:"); //建立文本框,设置属性
IsArea=new TextArea(30,80);
IsArea.setEditable(false); GBC.gridwidth=GridBagConstraints.REMAINDER;
GBC.fill =GridBagConstraints.HORIZONTAL;
((GridBagLayout)getLayout()).setConstraints(LblPrompt,GBC);
add(LblPrompt); GBC.gridwidth=1;
((GridBagLayout)getLayout()).setConstraints(LblHost,GBC);
add(LblHost);
GBC.gridwidth=GridBagConstraints.REMAINDER;
((GridBagLayout)getLayout()).setConstraints(TxtHost,GBC);
add(TxtHost); GBC.gridwidth=1;
((GridBagLayout)getLayout()).setConstraints(LblUID,GBC);
add(LblUID);
GBC.gridwidth=1;
((GridBagLayout)getLayout()).setConstraints(TxtUID,GBC);
add(TxtUID); GBC.gridwidth=1;
((GridBagLayout)getLayout()).setConstraints(LblPWD,GBC);
add(LblPWD);
GBC.gridwidth=1;
((GridBagLayout)getLayout()).setConstraints(TxtPWD,GBC);
add(TxtPWD);
GBC.gridwidth=1;
GBC.weightx=2;
((GridBagLayout)getLayout()).setConstraints(BtnConn,GBC);
add(BtnConn);
GBC.gridwidth=GridBagConstraints.REMAINDER; ((GridBagLayout)getLayout()).setConstraints(BtnClose,GBC);
add(BtnClose); GBC.gridwidth=GridBagConstraints.REMAINDER;
GBC.fill =GridBagConstraints.HORIZONTAL;
((GridBagLayout)getLayout()).setConstraints(IsArea,GBC);
add(IsArea);}public boolean connect(String hostname,String uid,String pwd)
{
this.hostname=hostname;
LblPrompt.setText("正在连接,请等待~~~~~~");
try
{
aftp=new FtpClient(hostname);
aftp.login(uid,pwd);
aftp.binary();
showFileContents();
}
catch(FtpLoginException e)
{
a="无权限与主机:"+hostname+"连接!";
LblPrompt.setText(a);
return false;
}
catch(IOException e)
{
a="连接主机"+hostname+"失败!";
LblPrompt.setText(a);
return false;
}
catch(SecurityException e)
{
a="无权限与主机:"+hostname+"连接!";
LblPrompt.setText(a);
return false;
}
LblPrompt.setText("连接主机:"+hostname+"成功!");
return true;}public void stop()
{
try
{
aftp.closeServer();
}
catch(IOException e)
{}
}public boolean action(Event evt,Object obj)
{
if(evt.target==BtnConn)
{
LblPrompt.setText("正在连接,请等待~~~~");
if(connect(TxtHost.getText(),TxtUID.getText(),TxtPWD.getText()))
{
BtnConn.setEnabled(false);
BtnClose.setEnabled(true);
}
return true;
} if(evt.target==BtnClose)
{
stop();
BtnConn.enable(true);
BtnClose.enable(false);
LblPrompt.setText("与主机"+hostname+"连接己断开!");
return true;
} return super.action(evt,obj);}public boolean sendFile(String filepathname)
{
boolean result=true;
if(aftp!=null)
{
LblPrompt.setText("正在粘贴文件,请耐心等待~~~~~~~");
String contentperline;
try
{
a="粘贴成功!";
String fg=new String("\\");
int index=filepathname.lastIndexOf(fg);
String filename=filepathname.substring(index+1);
File localFile;
localFile=new File(filepathname);
RandomAccessFile sendFile=new RandomAccessFile(filepathname,"r");
//上载文件
sendFile.seek(0);
outs=aftp.put(filename);
outputs=new DataOutputStrean(outs);
while(sendFile.getFilePointer()<sendFile.length())
{
ch=sendFile.read();
outputs.write(ch);
}
outs.close();
sendFile.close();
}
catch(IOException e)
{
a="粘贴失败!";
result=false;
}
LblPrompt.setText(a);
showFileContents();
}
else
{
result=false;
}
return result;}
public void showFileContents()
{
StringBuffer buf=new StringBuffer();
IsArea.setText("");
try
{
ins=aftp.list();
while((ch=ins.read())>=0)
{
buf.append((char)ch);
}
IsArea.appendText(buf.toString());
ins.close();
}
catch(IOException e) {}}public static void main(String args[])
{
Frame f=new Frame("FTP Client");
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
//退出系统
System.exit(0);
} });
useFtpApplet ftp=new useFtpApplet();
ftp.init();
ftp.start();
f.add(ftp);
f.pack();
f.setVisible(true);
}}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货