第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

JCIFS SmbFile RenameTo 無(wú)法移動(dòng)文件

JCIFS SmbFile RenameTo 無(wú)法移動(dòng)文件

慕村225694 2021-12-18 15:14:46
我有使用 JCIFS SmbFile.renameTo() 方法的最奇怪的行為。當(dāng)我執(zhí)行下面的代碼時(shí),它應(yīng)該將網(wǎng)絡(luò)文件從 test1 移動(dòng)到 test2,但它會(huì)在 test2 中創(chuàng)建一個(gè)名為 test.xml 的文件夾并拋出以下錯(cuò)誤“當(dāng)該文件已經(jīng)存在時(shí)無(wú)法創(chuàng)建文件...”我可以想不通 為什么這種方法會(huì)這樣做? NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication (sDomain,                                        sUsername, sPassword); SmbFile smbFromFile = new SmbFile("smb://test1/test.xml", auth); SmbFile smbToFile = new SmbFile("smb://test2/test.xml", auth); smbFromFile.renameTo(smbToFile);
查看完整描述

2 回答

?
GCT1015

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超4個(gè)贊

copyTo(SmbFile)和之間有一個(gè)有趣的區(qū)別renameTo(SmbFile)- 只有其中一個(gè)說(shuō)此文件和目標(biāo)文件不需要在同一主機(jī)上。由于renameTo(SmbFile)它沒(méi)有說(shuō),我只能假設(shè),你應(yīng)該使用copyTo,然后delete()將原來(lái)的。


SmbFile smbFromFile = new SmbFile("smb://test1/test.xml", auth);

SmbFile smbToFile = new SmbFile("smb://test2/test.xml", auth);

// smbFromFile.renameTo(smbToFile);

smbFromFile.copyTo(smbToFile);

smbFromFile.delete();


查看完整回答
反對(duì) 回復(fù) 2021-12-18
?
心有法竹

TA貢獻(xiàn)1866條經(jīng)驗(yàn) 獲得超5個(gè)贊

有兩種可能的場(chǎng)景:


1.)文件需要移動(dòng)到同一臺(tái)服務(wù)器上(即輸入文件夾和輸出文件夾的認(rèn)證細(xì)節(jié)是相同的)。


使用 renameTo() 方法。


 public boolean moveFile(SmbFile file) {

    log.info("{"Started Archiving or Moving the file");

    String targetFilePath = this.archiveDir + file.getName(); //Path where we need to move that file.

    try {

        NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("", userId, userPassword);

        log.info("targetFilePath: {} , currentFile : {}",targetFilePath, file);

        SmbFile targetFile = new SmbFile(targetFilePath, auth); 

          //authenticate the SmbFile

        try {

            file.renameTo(targetFile); //User renameTo method for same server

            log.info("Archived File : {} to: {}", file.getName(), 

            targetFile.getName());

            return true;

        } catch (SmbException e) {

            log.error("Unable to Archive File: {}", file.getName());

            return false;

        }

    } catch (MalformedURLException e) {

        log.error("Connection failed to Server Drive: {}", targetFilePath);

    }

    return false;

}

2.)文件需要在不同的服務(wù)器上移動(dòng)(即輸入文件夾和輸出文件夾的身份驗(yàn)證詳細(xì)信息 不相同)。


使用 copyTo() 方法。


在這里,我建議,您可以首先驗(yàn)證存在文件的第一臺(tái)服務(wù)器,并檢查文件是否存在,如果存在,則將其添加到列表中:


public List<SmbFile> xmlFiles = new ArrayList<>(); //Here we will add all the files which are existing.


public boolean isFileExists() throws MalformedURLException, SmbException {

  NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("", 

  userID, userPassword); //authenticating input folder.

    SmbFile smbFile = new SmbFile(inputFolder, auth);

    SmbFile[] smbFiles = smbFile.listFiles();

    boolean isFilePresent = false;

    if (smbFiles.length > 0) {

        for (SmbFile file : smbFiles) {

            if (file.getName().toLowerCase(Locale.ENGLISH)              

       .contains(AppConstant.FILE_NAME.toLowerCase(Locale.ENGLISH))) {

                xmlFiles.add(file);

                isFilePresent = true;

            }

        }

    }

    if (isPlanFilePresent) {

        log.info("Number of files present on Server: {}",smbFiles.length);

        return true;

    }

    return false;

}

這將為您提供列表中的文件。繼續(xù)將其復(fù)制到另一臺(tái)服務(wù)器。請(qǐng)注意,您只需要在此處對(duì)輸出文件夾進(jìn)行身份驗(yàn)證。


 public boolean moveFile(SmbFile file) {

    log.info("Started Moving or Archiving the file");

    String toFilePath = this.outputFolder + file.getName(); //path where you need to copy the file from input folder.

    try {

        NtlmPasswordAuthentication auth1 = new NtlmPasswordAuthentication("", outputFolderUserId, outputFolderPassword); //authenticating output folder

        log.info("targetFilePath: {} and currentFile : {}", toFilePath, file);

        SmbFile targetFile = new SmbFile(toFilePath, auth1);

      

        try {

            file.copyTo(targetFile);

            file.delete(); //delete the file which we copied at our desired server

            log.info("Archived File : {} to: {}", file.getName(), targetFile.getName());

            return true;

        } catch (SmbException e) {

            log.error("Unable to Archive File: {}", file.getName());

            return false;

        }


    } catch (MalformedURLException e) {

        log.error("Connection failed to Server Drive: {}", toFilePath);

    }

    return false;

}

很高興能幫助你 :)


查看完整回答
反對(duì) 回復(fù) 2021-12-18
  • 2 回答
  • 0 關(guān)注
  • 481 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)