欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

java使用apache commons的FTPClient删除文件,commonsftpclient,package cn.o

来源: javaer 分享于  点击 8904 次 点评:202

java使用apache commons的FTPClient删除文件,commonsftpclient,package cn.o


package cn.outofmemory.snippets.core;import org.apache.commons.net.ftp.FTPClient;import java.io.IOException;public class DeleteFileFtp {    public static void main(String[] args) {        FTPClient client = new FTPClient();        try {            client.connect("ftp.xxx.com");            client.login("username", "password");            // Set a string with the file you want to delete            String filename = "/coomons/footer.jsp";            // Delete file            boolean exist = client.deleteFile(filename);            // Notify user for deletion             if (exist) {                System.out.println("File '"+ filename + "' deleted...");            }            // Notify user that file doesn't exist            else                 System.out.println("File '"+ filename + "' doesn't exist...");            client.logout();        } catch (IOException e) {            e.printStackTrace();        } finally {            try {                client.disconnect();            } catch (IOException e) {                e.printStackTrace();            }        }    }}

输出:

File '/coomons/footer.jsp'  deleted...
相关栏目:

用户点评