引き波は、JavaのNIO Webサーバに基づいて広く使われている、ビルトインPathResourceManager、直接ファイルシステムにアクセスするために使用することができます提供している、あなたは、FTPに加えて、ファイルへの外部アクセスを提供する必要がある場合は、nginxの、など、引き波は、javaとしても良い選択です開発は、サービスを構築するのは非常に簡単です
セットアップサービス
Mavenのクイックスタートプロジェクトを作成し、ポンポン、ポンポンの参照設定で引き波を導入:
<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>
<groupId>com.iflytek</groupId>
<artifactId>fileserver</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>fileserver</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-core</artifactId>
<version>2.0.22.Final</version>
</dependency>
</dependencies>
</project>
ここに私のプロジェクト構造です:
以下のようにファイルサーバのコードであることを特徴とします。
package com.iflytek.fileserver;
import java.io.File;
import io.undertow.Handlers;
import io.undertow.Undertow;
import io.undertow.server.handlers.resource.PathResourceManager;
public class FileServer {
public static void main(String[] args) {
File file = new File("/");
Undertow server = Undertow.builder().addHttpListener(8080, "localhost")
.setHandler(Handlers.resource(new PathResourceManager(file.toPath(), 100))
.setDirectoryListingEnabled(true))
.build();
server.start();
}
}
まあ!主な機能を実行し、アクセスするためのブラウザ開くにhttp:// localhostを:8080
取得するためのコードの簡単な数行!