Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java AndroidRestlet框架-获取文件列表并下载文件_Java_Android_Restlet_Restlet 2.0 - Fatal编程技术网

Java AndroidRestlet框架-获取文件列表并下载文件

Java AndroidRestlet框架-获取文件列表并下载文件,java,android,restlet,restlet-2.0,Java,Android,Restlet,Restlet 2.0,我的应用程序中有Restlet服务器,如果我在浏览器中打开服务器地址,则服务器应返回某个文件夹中的文件列表,如果用户单击该文件,则应下载该文件 我看了这个。第6部分提供静态文件。这是一个代码: public static final String ROOT_URI = "file:///c:/restlet/docs/api/"; [...] // Create a component Component component = new Component(); component.getS

我的应用程序中有Restlet服务器,如果我在浏览器中打开服务器地址,则服务器应返回某个文件夹中的文件列表,如果用户单击该文件,则应下载该文件

我看了这个。第6部分提供静态文件。这是一个代码:

public static final String ROOT_URI = "file:///c:/restlet/docs/api/";

[...]

// Create a component
Component component = new Component();
component.getServers().add(Protocol.HTTP, 8182);
component.getClients().add(Protocol.FILE);

// Create an application
Application application = new Application() {
    @Override
    public Restlet createInboundRoot() {
            return new Directory(getContext(), ROOT_URI);
    }
};

// Attach the application to the component and start it
component.getDefaultHost().attach(application);
component.start();
但是如果我使用例如
file:///sdcard/
在URI中,如果我在浏览器中打开地址,则会得到

未找到

服务器未找到任何与请求URI匹配的内容

您可以在这里获得技术细节。

请继续访问我们的主页。

怎么了?如何使用Restlet返回文件列表?

我的解决方案:

    mWebServerComponent = new Component();
    mWebServerComponent.getClients().add(Protocol.FILE);
    mWebServerComponent.getServers().add(Protocol.HTTP, 8182);
    mWebServerComponent.getDefaultHost().attach(new FileApplication());
    try {
        mWebServerComponent.start();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
以及FileApplication类:

public class FileApplication extends Application {

// for example: public static final String ROOT_URI =
// "file:///C:/restlet-jee-2.0.6/docs/api/";
@Override
public synchronized Restlet createInboundRoot() {

    String ROOT_URI = "file:///"
            + Environment.getExternalStorageDirectory() + "/";

    Directory directory = new Directory(getContext(),
            LocalReference.localizePath(ROOT_URI));
    directory.setListingAllowed(true);
    Router router = new Router(getContext());

    router.attach("/files", directory);

    return router;
}
}