我试图在运行时创建一个目录,但是没有创建目录

时间:2017-03-24 15:07:04

标签: java android

//尝试使用ftp上传文件,正在上传文件但是我无法在我的ftp服务器上创建目录。

public void uploadFile(){

    FTPClient client = new FTPClient();
    client.enterLocalPassiveMode();
    try {
        client.connect(FTP_HOST,21);
        client.login(FTP_USER, FTP_PASS);

        // If directory is not created
        boolean chk=client.changeWorkingDirectory("/files/"+val_spsem+"/"+val_spsubj+"/");
        if(!chk)
        { // I am trying to create a directory here
            client.makeDirectory("/files/"+val_spsem+"/"+val_spsubj+"/");
            client.changeWorkingDirectory("/files/"+val_spsem+"/"+val_spsubj+"/");
        }

        //Logic ends

        File firstLocalFile = new File(path);
        InputStream inputStream = new FileInputStream(firstLocalFile);
        String firstRemoteFile=file_nm;
        client.setFileType(FTPClient.BINARY_FILE_TYPE);
        boolean done=client.storeFile(firstRemoteFile,inputStream);
        if(done)
        {
            //Toast.makeText(sub_sem.this,"Upload Completed",Toast.LENGTH_LONG).show();

            System.out.println("Upload Completed");
        }
    } catch (Exception e) {
        e.printStackTrace();
        try {
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }
}

0 个答案:

没有答案