【发布时间】:2015-05-17 17:42:23
【问题描述】:
我正在使用 JFrame GUI 在 Java 中编写一个简单的应用程序。在 GUI 中,我有 2 个字段(用于 ip 和文件夹)和 1 个用于我要连接的端口号的微调器。我可以连接到我的服务器http://147.230.75.240:8080/。但这条路完全是空的,我需要更深入地了解http://147.230.75.240:8080/sti。但我不知道如何实现这一目标。正如我所说,默认连接中没有文件夹。我怎样才能专门连接到这部分? 你可以在下面看到我的代码:
private void connectButtonActionPerformed(java.awt.event.ActionEvent evt) {
Socket socket = null;
String ip;
int port;
String folder;
ip = ipField.getText();
port = (int) portField.getValue();
folder = folderField.getText();
try {
File[] files = new File(folder).listFiles();
System.out.println(files);
socket = new Socket(InetAddress.getByName(ip), port);
connectionStatus.setText("Connected");
} catch (IOException ex) {
Logger.getLogger(ConnectForm.class.getName()).log(Level.SEVERE, null, ex);
}
}
这种情况下的文件返回 null。
【问题讨论】:
-
您是在尝试列出本地文件夹的内容还是由 HTTP 服务器提供的内容?
-
我正在尝试列出我正在连接的服务器的内容
-
I am trying to list the content of the server I am connecting to内容是指网页内容吗?见docs.oracle.com/javase/tutorial/networking/urls/… -
Swing、NetBeans 和 JFrame 都与这个问题无关。