有没有一种方法可以创建一个界面来显示Java中来自FTP服务器的档案?

时间:2019-01-08 17:13:54

标签: java swing

我有一个FTP服务器,我想使用一些图形源(例如,swing)来显示该服务器上存在的所有档案。

我尝试获取文件的名称,但是它并没有真正显示档案本身,除此之外没有找到其他解决方案。

该功能在该项目中并没有真正起作用,我真的不知道为什么它没有响应,但是在其他项目中使用它却按预期运行。

package view;

import javax.swing.JFrame;
import java.awt.EventQueue;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import java.util.ArrayList;

import org.apache.commons.net.ftp.FTPClient;

import java.io.*;

import br.com.consiste.FtpConnector.*;
import java.awt.List;
import java.awt.Button;

public class ViewTela {

private JFrame frmServidorFtp;

/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                ViewTela window = new ViewTela();
                window.frmServidorFtp.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the application.
 * 
 * @throws IOException
 */
public ViewTela() throws IOException {
    initialize();
}

/**
 * Initialize the contents of the frame.
 * 
 * @throws IOException
 */
private void initialize() throws IOException {

    frmServidorFtp = new JFrame();
    frmServidorFtp.setTitle("Servidor FTP");
    frmServidorFtp.setBounds(100, 100, 375, 445);
    frmServidorFtp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frmServidorFtp.getContentPane().setLayout(null);

    List list = new List();
    list.setBounds(10, 43, 339, 147);
    frmServidorFtp.getContentPane().add(list);

    Button button = new Button("New button");
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

        }
    });
    button.setBounds(35, 224, 84, 33);
    frmServidorFtp.getContentPane().add(button);

    FTPConnection connect = new FTPConnection();
    FTPClient ftpClient = connect.createConnection();
    FTPUtil util = new FTPUtil();

    ArrayList<String> pastes = util.listPastes(ftpClient);
    int size = util.listPastes(ftpClient).size();
    System.out.println(size);

    for (int index = 0; index < size; index++) {
        pastes.get(index);
    }
}
}

我的POM文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.1.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>br.com.consiste</groupId>
    <artifactId>FtpInterface</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>FtpInterface</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>br.com.consiste</groupId>
            <artifactId>FtpConnector</artifactId>
            <version>1.0.0</version>
            <scope>compile</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

0 个答案:

没有答案