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

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

在 FTP 中讀取 file.xml

在 FTP 中讀取 file.xml

拉丁的傳說 2021-10-28 16:57:49
我在 FTP 中讀取 .xml 文件時(shí)出現(xiàn)問題,出現(xiàn)以下消息:“ftp:\cifpag\FilesNotes\Maxdata_Venda_209016.XML(文件名、目錄名或卷標(biāo)的語法不正確)”,在該代碼對(duì)已經(jīng)完成的測(cè)試以及每個(gè)步驟中發(fā)生的情況進(jìn)行了評(píng)論,它遵循以下代碼:公共類 ImportXmlFromFTP {private static Connection conexao;private String endereco_ftp; private String usuario;private String senha;private String caminho_ftp;private String caminho_local;private String valor;public ImportXmlFromFTP(){}public void inicia() throws SocketException, IOException, SQLException {    //DADOS CONEXAO    this.conexao = ConexaoBancoDeDados.getConexao();      String sql = "SELECT daea_endereco_ftp, daea_usuario, daea_senha, daea_caminho_ftp, daea_caminho_local FROM sistema.dados_envio_arquivos";    PreparedStatement stmtSelect = this.conexao.prepareStatement(sql);    ResultSet rs = stmtSelect.executeQuery();    List<DadosEnviaArquivos> listaCliente = new ArrayList<DadosEnviaArquivos>();    while(rs.next()){        DadosEnviaArquivos dados = new DadosEnviaArquivos();        endereco_ftp = rs.getString("daea_endereco_ftp");        usuario = rs.getString("daea_usuario");        senha = rs.getString("daea_senha");        caminho_ftp = rs.getString("daea_caminho_ftp");        caminho_local = rs.getString("daea_caminho_local");    }    
查看完整描述

2 回答

?
HUX布斯

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

我能夠通過將 XML 文件轉(zhuǎn)換為字符串然后返回為 xml 來執(zhí)行代碼,我希望它對(duì)某人有所幫助。


public class MyFTPClass {


private static FTPFile[] obterArquivosDiretorio(FTPClient ftp, String dirPath) throws IOException {

    String cwd = ftp.printWorkingDirectory();


    ftp.changeWorkingDirectory(dirPath);

    FTPFile[] files = ftp.listFiles();

    ftp.changeWorkingDirectory(cwd);


    return files;

}


public static void main(String args[]) throws SAXException, ParserConfigurationException {


    // Create an instance of FTPClient

    FTPClient ftp = new FTPClient();

    try {


        // Establish a connection with the FTP URL

        ftp.connect("caminho_ftp");

        // Enter user details : user name and password

        boolean isSuccess = ftp.login("usuario", "senha");


        if (isSuccess) {

            // Fetch the list of names of the files. In case of no files an

            // empty array is returned


            String path = "ArquivosNotas";

            FTPFile[] listedDirectories = obterArquivosDiretorio(ftp, path);


            int countXml = 1;

            // Iterate on the returned list to obtain name of each file

            for (FTPFile file : listedDirectories) {


                if (file.getName().toLowerCase().contains("xml")) {


                    System.out.println();

                    System.out.println("Lendo " + countXml + " xml");

                    System.out.println();


                    InputStream stream = ftp.retrieveFileStream("ArquivosNotas/" + file.getName());

                    BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));


                    // xml vai virar uma string para depois fazer o parse para o document

                    StringBuilder sb = new StringBuilder();

                    String inline = "";

                    while ((inline = reader.readLine()) != null) {

                        sb.append(inline);

                    }


                    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

                    DocumentBuilder builder = factory.newDocumentBuilder();


                    // convert string do xml para xml em document

                    Document doc = (Document) builder.parse(new ByteArrayInputStream(sb.toString().getBytes()));


                    NodeList listaDeVenda = doc.getElementsByTagName("venda");

                    int tamanhoDaLista = listaDeVenda.getLength();


                    NodeList listaDeProdutos = doc.getElementsByTagName("item");

                    int tamanhoDaListaDeProdutos = listaDeProdutos.getLength();


                    System.out.println();

                    System.out.println("Qtde itens xml " + tamanhoDaListaDeProdutos);


                    System.out.println("Finalizado " + countXml + " xml");

                    System.out.println();

                    countXml++;


                    stream.close();

                    reader.close();

                    ftp.completePendingCommand();

                }


            }

        }


        ftp.logout();

    } catch (IOException e) {

        e.printStackTrace();

    } finally {

        try {

            ftp.disconnect();

        } catch (IOException e) {

            e.printStackTrace();

        }

    }

}

}


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

添加回答

舉報(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)