【Java实现FTP服务】笔记06.05——动手

高手当笑话看吧。

这是我们专业二年级的综合实训课题,表示刚学Java,有压力啊!

课题简述:要求有服务端和客户端。服务端即实现基本ftp功能,包括文件、目录操作,文件的传输,支持断点续传。客户端无特别要求,简单使用即可,分管理员和普通用户。

今天的笔记:

1、Java的获取键盘输入貌似有点麻烦。

String command;//用作获得命令
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
try{
    command=stdIn.readLine();//此处要求异常处理
}catch(IOException e){
    System.out.println("输入错误,请检查输入设备...");
    break;
}

2、字符串的简单处理

/*这是在一个while循环*/
if(command.startsWith("conn ")){
/*public boolean startswith(String str)方法判断字符串是否以str字符串开头*/
    String url;
    url=command.substring(5);/*public String substring(int index)方法截取从第index开始到最后的字符串*/
    user.Conn(url);    /*函数调用,忽略……*/
    break;
}else if(command.equals("quit")){
/*equals方法判断command是否与“quit”相同*/
    break;
}
String host[]=url.split(":");    //public String[] split(char ch)方法将字符串以ch分割,依次复制给字符串数组;
try{
    int port=Integer.parseInt(host[1]);    //把字符串转为整型(会抛出异常)
}catch(NumberFormatException e){
    System.out.println("端口号错误!");
}

暂时就这样吧,希望大神指点指点^_^

 

posted @ 2013-06-05 21:10  shhider  阅读(427)  评论(0编辑  收藏  举报