当前位置: 代码迷 >> Java相关 >> [求助]小弟新学JAVA,有'class' or 'interface' expected郁闷问题求教大虾
  详细解决方案

[求助]小弟新学JAVA,有'class' or 'interface' expected郁闷问题求教大虾

热度:655   发布时间:2005-12-29 15:16:00.0
[求助]小弟新学JAVA,有'class' or 'interface' expected郁闷问题求教大虾

小弟新学JAVA,有'class' or 'interface' expected郁闷问题求教大虾
从网上DOWN饿几个源程序,只要是里面有package 的,必定在第2次出现这一行时出错:C:\Program Files\netbeans-4.0\$PROJECTHOME\cn.edu.bit.software.ftptrans\src\cn\edu\bit\software\ftptrans\cn.edu.bit.software.ftptrans.java:128: 'class' or 'interface' expected

例如这个。原吗如下:
package cn.edu.bit.software.ftptrans;
import java.io.*;
import java.net.*;
import java.util.Vector;
import java.util.logging.*;

public class FtpServer
{
//客户端socket对象
private ServerSocket m_servSocket;

//ftp服务器的端口号
private int SERVER_PORT;

//ftp服务器所允许的最大连接数
private int MAX_CONN;

//连入的客户端处理对象管理器
private Vector vecClient;

//设定一个log日志对象
private Logger mylog;

private ConsoleHandler handler;

String strServHome;

public FtpServer(int servPort, int maxConn)
{
SERVER_PORT = servPort;
MAX_CONN = maxConn;
strServHome = "c:\\";
vecClient = new Vector();
/*------------初始化log------------*/
try
{
handler = new ConsoleHandler();
handler.setLevel(Level.ALL);
mylog = Logger.getLogger("FtpServer");
mylog.addHandler(handler);
mylog.setLevel(Level.ALL);
}
catch (SecurityException e)
{
mylog.warning("在设置程序日志级别时出现异常");
mylog.warning(e.getMessage());
}

/*--------------初始化服务器,端口2121----------------------*/
try
{
m_servSocket = new ServerSocket(SERVER_PORT, MAX_CONN);
while (true)
{
mylog.finest("FtpServer开始在端口2121监听");
Socket clientSocket = m_servSocket.accept();
vecClient.add(clientSocket);
mylog.info("#" + vecClient.size() + "号客户端连入");
new TransHandler(this, clientSocket, vecClient.size()).start();
}
}
catch (IOException e)
{
mylog.warning("在初始化FtpServ时出现错误");
mylog.warning(e.getMessage());
}
}

public void deleteClient(TransHandler handler)
{
try
{
vecClient.remove(handler);
vecClient.setSize(vecClient.size() - 1);
mylog.info("第#" + handler.iClientNum + "号客户端断开了与服务器的连接!");
}
catch (Exception e)
{
mylog.warning("在删除第#" + handler.iClientNum + "号客户端时出现异常");
mylog.warning(e.getMessage());
}
}

public static void main(String[] args)
{
new FtpServer(2121, 50);
}
}

/**
* 当有客户端连入时,处理客户端请求的类
* @author findfrog
* @version 1.0
*/
class TransHandler extends Thread
{
//服务器句柄,用于最后销毁TransHandler对象时用
FtpServer main = null;
//客户端的socket
private Socket m_clientSocket = null;

//日志对象
private Logger mylog;

//要上传的文件路径
private String strUpFilePath = null;

//要下载的文件路径
private String strDnFilePath = null;

//本客户端在的序号
int iClientNum = -1;

//缓冲字节数据的大小
private int ibufferlength;

//缓冲字节数组
byte[] inputBytes;

//从客户端传来的指令
String strClientOrder;
//用于得到从socket端的输入信息
InputStream m_inputStream;
//用于向socket输出的输出流
OutputStream m_outputStream;
//用于上传文件的输出流
FileOutputStream m_fileOutputStream;
//用于下载文件的输入流
FileInputStream m_fileInputStream;

//构造函数
public TransHandler(FtpServer fserver, Socket s, int iNum)
{
try
{
main = fserver;
//将客户端socket句柄付给本地对象
m_clientSocket = s;
//初始化log对象
mylog = Logger.getLogger("TransHandler");
//初始化本客户端序号
iClientNum = iNum;
//用于得到从socket端的输入信息
m_inputStream = m_clientSocket.getInputStream();
m_outputStream = m_clientSocket.getOutputStream();
ibufferlength = 1024;
inputBytes = new byte[ibufferlength + 12];

}
catch (Exception e)
{
mylog.warning("在初始化TransHandler时发生异常!");
mylog.warning(e.getMessage());
}
}

public void run()
{
try
{
int ilength;
while ( (ilength = m_inputStream.read(inputBytes, 0, 12 + ibufferlength)) !=
-1)
{
strClientOrder = new String(inputBytes, 0, 7);
if (strClientOrder.equals("DISCONN"))
{ //断开连接
mylog.info("得到了DISCONN");
exit();
}
else if (strClientOrder.equals("LSFILES"))
{ //发送当前目录文件列表
mylog.info("服务器端接收到了LSFILES命令");
File flHome = new File(main.strServHome);
String[] strFileNames = flHome.list();
strFileNames = AdjustStrings(strFileNames);
for (int i = 0; i < strFileNames.length; i++)
{
String strFileNameLength = publicFunc.formatLength(strFileNames[i].
getBytes().length);
byte[] fileNameBytes = strFileNames[i].getBytes();
byte[] outBytes = publicFunc.makepackage("LSFILES",
strFileNameLength, fileNameBytes);
m_outputStream.write(outBytes, 0, outBytes.length);
m_outputStream.flush();
}
}
else if (strClientOrder.equals("ENDFILE"))
{ //上传一个文件的结束标记
mylog.info("收到文件结束标志符号");
m_fileOutputStream.close();
}
else if (strClientOrder.equals("UPFILEN"))
{ //表示要上传一个新的文件,并且此包中包含了文件名
int iFileNameLength = Integer.parseInt(new String(inputBytes, 7, 5));
mylog.info("要上传的文件名的长度为" + iFileNameLength);
String strFileName = new String(inputBytes, 12, iFileNameLength);
mylog.info("要上传的文件名是:" + strFileName);
//初始化上传文件路径
strUpFilePath = main.strServHome + strFileName;
File upFile = new File(strUpFilePath);
m_fileOutputStream = new FileOutputStream(upFile);
}
else if (strClientOrder.equals("UPDATAS"))
{ //表示本包是要上传的数据
//本次数据包的长度
mylog.info("正在接收文件...");
int iDataLength = Integer.parseInt(new String(inputBytes, 7, 5));
m_fileOutputStream.write(inputBytes, 12, iDataLength);
m_fileOutputStream.flush();
}
else if (strClientOrder.equals("DNFILEN"))
{ //表示要下载的文件名,服务器要执行向客户端传输文件的操作
int iFileNameLength = Integer.parseInt(new String(inputBytes, 7, 5));
mylog.info("要下载的文件名的长度为" + iFileNameLength);
String strFileName = new String(inputBytes, 12, iFileNameLength);
mylog.info("要下载的文件名是:" + strFileName);
//初始化上传文件路径
strDnFilePath = main.strServHome + strFileName;
File dnFile = new File(strDnFilePath);
//初始化了文件输出流
m_fileInputStream = new FileInputStream(dnFile);

//开始向客户端传输文件
mylog.info("开始向客户端传输文件" + strFileName + "...");
int iInputLength = 0;
String strInputLength;
byte[] readBytes = new byte[ibufferlength];
while ( (iInputLength = m_fileInputStream.read(readBytes, 0,
ibufferlength)) !=
-1)
{
strInputLength = publicFunc.formatLength(iInputLength);
byte[] outBytes = publicFunc.makepackage("DNDATAS", strInputLength,
readBytes);
m_outputStream.write(outBytes, 0, outBytes.length);
m_outputStream.flush();
}

//最后发送一个文件结束标记
m_outputStream.write(publicFunc.makepackage("ENDFILE", "00001",
new byte[1]));
m_outputStream.flush();
}
}
}
catch (Exception e)
{
mylog.warning(e.getMessage());
}
}

public void exit()
{
try
{
m_outputStream.write(publicFunc.makepackage("DISCONN", "00001",
new byte[1]));
m_inputStream.close();
m_outputStream.close();
main.deleteClient(this);
main = null;
}
catch (Exception e)
{
mylog.warning("在断开客户端#" + this.iClientNum + "连接时出现异常!");
mylog.warning(e.getMessage());
}
}

public String[] AdjustStrings(String[] strFileNames)
{
String[] strItemNames = new String[strFileNames.length + 1];
strItemNames[0] = "返回上一级";
int j = 1;
for (int i = 0; i < strFileNames.length; i++)
{
File upFile = new File(main.strServHome + strFileNames[i]);
if (!upFile.isFile())
{
strItemNames[j++] = "[文件夹]" + strFileNames[i];
}
}
for (int i = 0; i < strFileNames.length; i++)
{
File upFile = new File(main.strServHome + strFileNames[i]);
if (upFile.isFile())
{
strItemNames[j++] = strFileNames[i];
}
}

return strItemNames;
}

}

public class FtpClient extends Thread
{
Logger mylog = Logger.getLogger("FtpClient");
Socket m_clientSocket;
//缓冲字节数据的大小
private int ibufferlength;

//缓冲字节数组
byte[] inputBytes;

Vector vecServFiles;

//用于得到从socket端的输入信息
InputStream m_inputStream;
//用于向socket输出的输出流
OutputStream m_outputStream;
//向本地写文件的文件输出流
FileOutputStream m_fileOutputStream;
//从本地读文件的文件输入流
FileInputStream m_fileInputStream;
//从服务器端传来的指令
String strServerOrder;
//主机的ip地址
String strServerIP;
//服务器的端口号
int iServerPort;

public FtpClient(String strServIP, int iServPort)
{
strServerIP = strServIP;
iServerPort = iServPort;
}

public void run()
{
try
{
//建立连接
m_clientSocket = new Socket(strServerIP, iServerPort);
mylog.info("已经连到了主机" + strServerIP + "在端口" + iServerPort);
m_inputStream = m_clientSocket.getInputStream();
m_outputStream = m_clientSocket.getOutputStream();
mylog.fine("客户端得到了socket的输入输出流!");
ibufferlength = 1024;
inputBytes = new byte[ibufferlength + 12];
vecServFiles = new Vector();
doBusiness();
}
catch (UnknownHostException e)
{
mylog.warning("服务器地址未知");
mylog.warning(e.getMessage());
}
catch (IOException e)
{
mylog.warning(e.getMessage());
}
catch (Exception e)
{
mylog.warning(e.getMessage());
}
}

public void doBusiness()
{
try
{
int iLength = 0;
while ( (iLength = m_inputStream.read(inputBytes, 0, ibufferlength + 12)) !=
-1)
{
strServerOrder = new String(inputBytes, 0, 7);
if (strServerOrder.equals("DISCONN"))
{ //断开连接
mylog.info("在client端得到了DISCONN");
int length = Integer.parseInt(new String(inputBytes, 7, 5));
mylog.info("长度是" + length);
}
else if (strServerOrder.equals("LSFILES"))
{ //接收服务器当前目录文件列表

int iDataLength = Integer.parseInt(new String(inputBytes, 7, 5));
mylog.info("在客户端这个文件名的长度是:" + iDataLength);
String strFileName = new String(inputBytes, 12, iDataLength);
mylog.info("客户端正在获取服务器目录信息....." + strFileName);
vecServFiles.add(strFileName);
}
else if (strServerOrder.equals("ENDFILE"))
{ //下载一个文件的结束标记
mylog.info("收到下载文件结束标志符号");
m_fileOutputStream.close();
}
else if (strServerOrder.equals("DNDATAS"))
{ //表示本包是要下载的数据
int iDataLength = Integer.parseInt(new String(inputBytes, 7, 5));
m_fileOutputStream.write(inputBytes, 12, iDataLength);
m_fileOutputStream.flush();
}
}
}
catch (Exception e)
{

}
}

/**
* 客户端上传文件名
* @param strFileName 要上传文件的文件名
*/
public void upFileName(String strFileName)
{
try
{
String strLength = publicFunc.formatLength(strFileName.getBytes().length);
byte[] outBytes = publicFunc.makepackage("UPFILEN", strLength,
strFileName.getBytes());
m_outputStream.write(outBytes, 0, outBytes.length);
m_outputStream.flush();
}
catch (Exception e)
{
mylog.warning("在客户端在向服务器写要上传的文件名时发生异常");
mylog.warning(e.getMessage());
}
}

/**
* 讲本地文件strFilePath上传到服务器
* @param strFilePath 本地文件路径
*/
public void upFileData(String strFilePath)
{
try
{
File file = new File(strFilePath);
m_fileInputStream = new FileInputStream(file);

int iInputLength = 0;
String strInputLength;
byte[] readBytes = new byte[ibufferlength];
while ( (iInputLength = m_fileInputStream.read(readBytes, 0,
ibufferlength)) !=
-1)
{
strInputLength = publicFunc.formatLength(iInputLength);
byte[] outBytes = publicFunc.makepackage("UPDATAS", strInputLength,
readBytes);
m_outputStream.write(outBytes, 0, outBytes.length);
m_outputStream.flush();
}
//最后发送一个文件结束标记

未完

搜索更多相关的解决方案: JAVA  interface  expected  class  

----------------解决方案--------------------------------------------------------
继续

m_outputStream.write(publicFunc.makepackage("ENDFILE", "00001",
new byte[1]));
m_outputStream.flush();
}
catch (Exception e)
{
mylog.warning("从客户端向服务器传输文件内容是发生异常");
mylog.warning(e.getMessage());
}
}

/**
* 讲本地文件strFilePath上传到服务器
* @param strFile 本地文件路径
*/
public void upFileData(File fl)
{
try
{
File file = fl;
m_fileInputStream = new FileInputStream(file);

int iInputLength = 0;
String strInputLength;
byte[] readBytes = new byte[ibufferlength];
while ( (iInputLength = m_fileInputStream.read(readBytes, 0,
ibufferlength)) !=
-1)
{
strInputLength = publicFunc.formatLength(iInputLength);
byte[] outBytes = publicFunc.makepackage("UPDATAS", strInputLength,
readBytes);
m_outputStream.write(outBytes, 0, outBytes.length);
m_outputStream.flush();
}
//最后发送一个文件结束标记
m_outputStream.write(publicFunc.makepackage("ENDFILE", "00001",
new byte[1]));
m_outputStream.flush();
}
catch (Exception e)
{
mylog.warning("从客户端向服务器传输文件内容是发生异常");
mylog.warning(e.getMessage());
}
}

/**
* 从服务器端得到文件,并把文件存在strFileName里
* @param strFileName String
*/
public void getFile(String strFilePath, String strFileName)
{
try
{
mylog.info("下载文件的路径是" + strFilePath);
//建立器本地文件的输出流
File file = new File(strFilePath);
m_fileOutputStream = new FileOutputStream(file);

mylog.info("要下载的文件名是:" + strFileName);
String strDataLength = publicFunc.formatLength(strFileName.getBytes().length);
byte[] outBytes = publicFunc.makepackage("DNFILEN", strDataLength,
strFileName.getBytes());
m_outputStream.write(outBytes, 0, outBytes.length);
m_outputStream.flush();
}
catch (Exception e)
{
mylog.warning("在从服务器下载文件是发生异常!");
mylog.warning(e.getMessage());
}
}

public void listFile()
{
try
{
byte[] outBytes = publicFunc.makepackage("LSFILES", "00001", new byte[1]);
m_outputStream.write(outBytes, 0, outBytes.length);
m_outputStream.flush();
mylog.info("发送了LSFILES命令");
}
catch (Exception e)
{
mylog.warning("在从客户端向服务器端发送LSFILES命令使出错");
mylog.warning(e.getMessage());
}
}

public Vector getFileList()
{
return vecServFiles;
}

public void disConnect()
{
try
{
byte[] outBytes = publicFunc.makepackage("DISCONN", "00000", new byte[1]);
m_outputStream.write(outBytes, 0, outBytes.length);
m_outputStream.flush();
mylog.info("发送了DISCONN命令");
}
catch (Exception e)
{
mylog.warning("在从客户端向服务器端发送DISCONN命令使出错");
mylog.warning(e.getMessage());
}
}

public static void main(String[] args)
{
FtpClient client = new FtpClient("127.0.0.1", 2121);
client.start();
try
{
Thread.sleep(1000);
}
catch (InterruptedException ex)
{
}
client.upFileName("client1.txt");
client.upFileData("e:\\client.txt");
}
}


/**
*

Title: Ftp客户端的用户界面


* @author findfrog
* @version 1.0
*/
public class FtpClientUI extends JFrame implements ActionListener
{
FtpClient client;
//第一层
JPanel m_jpnlTop; //顶端的JPanel
JPanel m_jpnlCenter; //中间的JPanel
JPanel m_jpnlBotton; //底端的JPanel

//顶端的布局变量
Dimension dmnTopLabel;
Dimension dmnTopTxfd;
Dimension dmnTopBtn;
JLabel m_jlbTopIP;
JLabel m_jlbTopPort;
JLabel m_jlbTopUsername;
JLabel m_jlbTopPassword;
JTextField m_jtxfdTopIP;
JTextField m_jtxfdTopPort;
JTextField m_jtxfdTopUsername;
JPasswordField m_jtxfdTopPassword;
JButton m_jbtnTopConn;
JButton m_jbtnTopDisconn;

//中间的布局变量
JPanel m_jpnlCenterLeft; //中间的JPanel靠左部分
JPanel m_jpnlCenterMiddle; //中间的JPanel靠中部分
JPanel m_jpnlCenterRight; //中间的JPanel靠右部分
Dimension m_dmnCenterLable;
Dimension m_dmnCenterFileChooser;
Dimension m_dmnCenterBtn;

//中间左边部分的布局变量
JLabel m_jlbCenterLeft;
JFileChooser m_jfcCenterLeft;
//中间中间部分的布局变量
JButton m_jbtnCenterMiddleUp;
JButton m_jbtnCenterMiddleDown;
//中间右边部分的布局变量
JLabel m_jlbCenterRight;
JScrollPane m_jscpCenterRight;
JList m_jlstCenterRight;
Vector m_vecCenterRight;

//底段的布局变量
JTextArea m_jtxarBotton;
JScrollPane m_jscpBotton;

public FtpClientUI() throws HeadlessException
{
super();
initInstance();
try
{
initInstance();
}
catch (Exception ex)
{
ex.printStackTrace();
}
}

public void initInstance()
{
//将顶层的Layout设为BorderLayout
Container container = this.getContentPane();
container.setLayout(new BorderLayout());
this.setSize(new Dimension(800, 600));
this.setTitle("TransFTP");

//设置顶层的上中下布局
m_jpnlTop = new JPanel();
m_jpnlCenter = new JPanel();
m_jpnlBotton = new JPanel();
container.add(m_jpnlTop, BorderLayout.NORTH);
container.add(m_jpnlCenter, BorderLayout.CENTER);
container.add(m_jpnlBotton, BorderLayout.SOUTH);

//设置顶层m_jpnlTop的布局
m_jpnlTop.setLayout(new FlowLayout());
dmnTopLabel = new Dimension(50, 20);
dmnTopTxfd = new Dimension(80, 20);
dmnTopBtn = new Dimension(80, 20);
m_jlbTopIP = new JLabel("IP:");
m_jlbTopPort = new JLabel("端口:");
m_jlbTopUsername = new JLabel("用户名:");
m_jlbTopPassword = new JLabel("密码:");
m_jtxfdTopIP = new JTextField();
m_jtxfdTopUsername = new JTextField();
m_jtxfdTopPassword = new JPasswordField();
m_jtxfdTopPort = new JTextField();
m_jtxfdTopPort.setText("2121");
m_jbtnTopConn = new JButton("连接");
m_jbtnTopDisconn = new JButton("断开");
m_jbtnTopConn.addActionListener(this);
m_jbtnTopDisconn.addActionListener(this);
//设置组件大小
m_jlbTopIP.setPreferredSize(dmnTopLabel);
m_jlbTopPort.setPreferredSize(dmnTopLabel);
m_jlbTopUsername.setPreferredSize(dmnTopLabel);
m_jlbTopPassword.setPreferredSize(dmnTopLabel);
m_jtxfdTopIP.setPreferredSize(dmnTopTxfd);
m_jtxfdTopPort.setPreferredSize(new Dimension(40, 20));
m_jtxfdTopUsername.setPreferredSize(dmnTopTxfd);
m_jtxfdTopPassword.setPreferredSize(dmnTopTxfd);
m_jbtnTopConn.setPreferredSize(dmnTopBtn);
m_jbtnTopDisconn.setPreferredSize(dmnTopBtn);
//使JLabel的文字右对齐
m_jlbTopIP.setHorizontalAlignment(SwingConstants.RIGHT);
m_jlbTopPort.setHorizontalAlignment(SwingConstants.RIGHT);
m_jlbTopUsername.setHorizontalAlignment(SwingConstants.RIGHT);
m_jlbTopPassword.setHorizontalAlignment(SwingConstants.RIGHT);
//将初始化的对象加到JPanel里去
m_jpnlTop.add(m_jlbTopIP);
m_jpnlTop.add(m_jtxfdTopIP);
m_jpnlTop.add(m_jlbTopUsername);
m_jpnlTop.add(m_jtxfdTopUsername);
m_jpnlTop.add(m_jlbTopPassword);
m_jpnlTop.add(m_jtxfdTopPassword);
m_jpnlTop.add(m_jbtnTopConn);
m_jpnlTop.add(m_jbtnTopDisconn);
m_jpnlTop.add(m_jlbTopPort);
m_jpnlTop.add(m_jtxfdTopPort);

//设置中间m_jpnlCenter的左中右布局
m_jpnlCenter.setLayout(new BorderLayout());
m_jpnlCenterLeft = new JPanel();
m_jpnlCenterMiddle = new JPanel();
m_jpnlCenterRight = new JPanel();
m_jpnlCenterLeft.setPreferredSize(new Dimension(350, 500));
m_jpnlCenterMiddle.setPreferredSize(new Dimension(100, 500));
m_jpnlCenterRight.setPreferredSize(new Dimension(350, 500));
//设置边框
m_jpnlCenterLeft.setBorder(new LineBorder(Color.CYAN, 2));
m_jpnlCenterMiddle.setBorder(new LineBorder(Color.CYAN, 2));
m_jpnlCenterRight.setBorder(new LineBorder(Color.CYAN, 2));
//设置大小
m_dmnCenterLable = new Dimension(350, 20);
m_dmnCenterFileChooser = new Dimension(350, 480);
m_dmnCenterBtn = new Dimension(80, 20);
m_jpnlCenter.add(m_jpnlCenterLeft, BorderLayout.WEST);
m_jpnlCenter.add(m_jpnlCenterMiddle, BorderLayout.CENTER);
m_jpnlCenter.add(m_jpnlCenterRight, BorderLayout.EAST);

//设置中间左边布局
m_jpnlCenterLeft.setLayout(new BorderLayout());
m_jlbCenterLeft = new JLabel("本地文件列表");
m_jlbCenterLeft.setHorizontalAlignment(SwingConstants.CENTER);
m_jlbCenterLeft.setPreferredSize(m_dmnCenterLable);
m_jfcCenterLeft = new JFileChooser();
m_jfcCenterLeft.setPreferredSize(m_dmnCenterFileChooser);
m_jpnlCenterLeft.add(m_jlbCenterLeft, BorderLayout.NORTH);
m_jpnlCenterLeft.add(m_jfcCenterLeft, BorderLayout.CENTER);

//设置中间中间部分的布局
m_jpnlCenterMiddle.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
m_jbtnCenterMiddleUp = new JButton("上传>>");
m_jbtnCenterMiddleDown = new JButton("<<下载");
m_jbtnCenterMiddleUp.addActionListener(this);
m_jbtnCenterMiddleDown.addActionListener(this);
m_jbtnCenterMiddleUp.setPreferredSize(m_dmnCenterBtn);
m_jbtnCenterMiddleDown.setPreferredSize(m_dmnCenterBtn);
gbc.gridy = 1;
gbc.weighty = 1;
m_jpnlCenterMiddle.add(m_jbtnCenterMiddleUp, gbc);
gbc.gridy = 2;
m_jpnlCenterMiddle.add(m_jbtnCenterMiddleDown, gbc);

//设置中间右边布局
m_jpnlCenterRight.setLayout(new BorderLayout());
m_jlbCenterRight = new JLabel("服务器文件列表");
m_jlbCenterRight.setHorizontalAlignment(SwingConstants.CENTER);
m_jlbCenterRight.setPreferredSize(m_dmnCenterLable);
m_vecCenterRight = new Vector();
m_jlstCenterRight = new JList(m_vecCenterRight);
m_jscpCenterRight = new JScrollPane(m_jlstCenterRight);
m_jscpCenterRight.setPreferredSize(m_dmnCenterFileChooser);
m_jpnlCenterRight.add(m_jlbCenterRight, BorderLayout.NORTH);
m_jpnlCenterRight.add(m_jscpCenterRight, BorderLayout.CENTER);

//设置底端底布局
m_jpnlBotton.setLayout(new BorderLayout());
m_jtxarBotton = new JTextArea();
m_jscpBotton = new JScrollPane(m_jtxarBotton);
m_jscpBotton.setPreferredSize(new Dimension(800, 80));
m_jpnlBotton.add(m_jscpBotton, BorderLayout.CENTER);
}

public void actionPerformed(ActionEvent e)
{
if (e.getSource() == m_jbtnTopConn)
{
doConnect();
}
else if (e.getSource() == m_jbtnTopDisconn)
{
doDisConnect();
}
else if (e.getSource() == m_jbtnCenterMiddleUp)
{
doUpFile();
}
else if (e.getSource() == m_jbtnCenterMiddleDown)
{
doDownFile();
}
}

public void doConnect()
{
int iPort = 2121;
try
{
iPort = Integer.parseInt(m_jtxfdTopPort.getText());
String strIP = m_jtxfdTopIP.getText();
if (strIP == null)
{
strIP = "127.0.0.1";
}
client = new FtpClient(strIP, iPort);
client.start();
int iConnNum = 0;
while (client.m_clientSocket == null)
{
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
m_jtxarBotton.append("系统提示:不能连接到服务器: " + strIP + ",在端口: " + iPort +
"\n");
}
if (iConnNum++ >= 5)
{
throw new Exception();
}
}

client.listFile();

try
{
Thread.sleep(1000);
}
catch (InterruptedException ex)
{
}
m_vecCenterRight = client.getFileList();
m_jlstCenterRight.setListData(m_vecCenterRight);
m_jtxarBotton.append("系统提示:连接到了服务器: " + strIP + ",在端口: " + iPort + "\n");
m_jtxarBotton.append("系统提示:成功获取服务器文件目录\n");
}
catch (NumberFormatException e)
{
m_jtxarBotton.append("系统提示:输入的端口号错误\n");
}
catch (Exception e)
{
m_jtxarBotton.append("系统提示:不能连接到服务器,请稍后在试\n");
}
}

public void doDisConnect()
{
client.disConnect();
m_vecCenterRight.removeAllElements();
m_jlstCenterRight.updateUI();
m_jtxarBotton.append("系统提示:失去了和服务器服务器的连接\n");
}

public void doUpFile()
{
try
{
File selectedFile = m_jfcCenterLeft.getSelectedFile();
client.upFileName(selectedFile.getName());
m_jtxarBotton.append("系统提示:正在上传文件" + selectedFile.getName() + "...\n");
client.upFileData(selectedFile);
client.listFile();
try
{
Thread.sleep(1000);
}
catch (InterruptedException ex)
{
}
m_vecCenterRight = client.getFileList();
m_jlstCenterRight.updateUI();
m_jtxarBotton.append("系统提示:文件" + selectedFile.getName() + "上传完毕\n");
}
catch (Exception e)
{
m_jtxarBotton.append("系统提示:在上传文件文件时出错\n");
m_jtxarBotton.append(e.getMessage());
}
}

public void doDownFile()
{
String strParentPath = "c:\\";
String strFileName;
try
{
File currentFile = m_jfcCenterLeft.getCurrentDirectory();
strParentPath = currentFile.getPath();
strFileName = (String) m_jlstCenterRight.getSelectedValue();

client.getFile(strParentPath + "\\" + strFileName, strFileName);
m_jtxarBotton.append("系统提示:文件" + strFileName + "下载完毕\n");
m_jfcCenterLeft.updateUI();
}
catch (NullPointerException e)
{
m_jtxarBotton.append("系统提示:请选择要下载的文件\n");
e.printStackTrace();
}

}

public static void main(String[] args)
{
FtpClientUI ftpclientui = new FtpClientUI();
ftpclientui.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
ftpclientui.show();
}

}


还有

}


----------------解决方案--------------------------------------------------------
出错在这

package cn.edu.bit.software.ftptrans; //出错在这里!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

public class publicFunc
{
public publicFunc()
{
}

public static byte[] makepackage(String strOrder, String strLength,
byte[] data)
{
int iOrderLength = strOrder.length();
int iLengthLength = strLength.length();
byte[] bytesOrder = strOrder.getBytes();
byte[] bytesLength = strLength.getBytes();
byte[] returnbytes = new byte[1036];
for (int i = 0; i < iOrderLength; i++)
{
returnbytes[i] = bytesOrder[i];
}
for (int i = iOrderLength; i < iLengthLength + iOrderLength; i++)
{
returnbytes[i] = bytesLength[i - iOrderLength];
}

for (int i = iLengthLength + iOrderLength;
i < data.length + iLengthLength + iOrderLength; i++)
{
returnbytes[i] = data[i - iLengthLength - iOrderLength];
}
return returnbytes;
}

public static String formatLength(int iLength)
{
int i = 0, j = 0, k = 0, l = 0, m = 0;
String strdata = new String("");
m = iLength % 10;
l = (iLength % 100) / 10;
k = (iLength % 1000) / 100;
j = (iLength % 10000) / 1000;
i = iLength / 10000;
strdata += String.valueOf(i) + String.valueOf(j) + String.valueOf(k) +
String.valueOf(l) + String.valueOf(m);
return strdata;
}
}
郁闷啊。。。


----------------解决方案--------------------------------------------------------
哼~~~
----------------解决方案--------------------------------------------------------
晕,这么长可看了很费眼睛的!!~~~~~
----------------解决方案--------------------------------------------------------
  相关解决方案